03 Regression
03 Regression
Regression
Lecture Overview
L MOUATASIM
Abdelkrim E AI
Full Professeur of (UIZ-FPO),
Winter term 2021/2022 Regression REG-2/55
Introduction
Solutions to Regression
Probabilistic Regression
Basis Function Regression
Wrap-Up
L MOUATASIM
Abdelkrim E AI
Full Professeur of (UIZ-FPO),
Winter term 2021/2022 Regression REG-3/55
Section:
Introduction
Introduction
Solutions to Regression
What is Regression?
Probabilistic Regression
Least Squares Error Function
Basis Function Regression
Wrap-Up
Regression
Type of target variable Continuous
Type of training information Supervised
Example Availability Batch learning
Algorithm sketch: Given the training data D, the algorithm derives a function of the
type
hθ (x ) = θ0 + θ1 x1 + · · · + θm xm x ∈ Rm , θ ∈ Rm+1 (1)
from the data. θ is the parameter vector containing the coecients to be estimated by
the regression algorithm. Once θ is learned, it can be used for prediction.
L MOUATASIM
Abdelkrim E AI
Full Professeur of (UIZ-FPO),
Winter term 2021/2022 Regression REG-5/55
Introduction
Solutions to Regression
What is Regression?
Probabilistic Regression
Least Squares Error Function
Basis Function Regression
Wrap-Up
hθ (x ) = θ0 + θ1 x1 + · · · + θm xm
• Usually: x0 = 1:
b ∈ Rm+1 = [1 x ]⊺
x
Xm
hθ (b
x) = θj xj = θ ⊺ xb
Marketing Expenses x1 j=0
L MOUATASIM
Abdelkrim E AI
Full Professeur of (UIZ-FPO),
Winter term 2021/2022 Regression REG-6/55
Introduction
Solutions to Regression
What is Regression?
Probabilistic Regression
Least Squares Error Function
Basis Function Regression
Wrap-Up
1 X
n
J(θ) = (hθ (b
x
(i)
) − y (i) )2 (2)
2n i=1
1 X
n
min (hθ (b
x
(i)
) − y (i) )2
θ 2n
i=1
2
Why the square
in the error function?
1
x
1 2 3 4 5 6 7 8 9
xb(i)
L MOUATASIM
Abdelkrim E AI
Full Professeur of (UIZ-FPO),
Winter term 2021/2022 Regression REG-8/55
Section:
Solutions to Regression
Introduction
Solutions to Regression
Closed-Form Solutions and Normal Equation
Probabilistic Regression
Gradient Descent
Basis Function Regression
Wrap-Up
Closed-Form Solutions
• Usual approach (for two unknowns): Calculate θ0 and θ1 according to
sample mean x Pn
(x (i) − x) · (y (i) − y )
θ0 = y − θ1 x θ1 = i=1Pn (i) − x)2
(3)
i=1 (x
y=
⊺
y (1) , y (2) , y (3) , . . . , y (n)
L MOUATASIM
Abdelkrim E AI
Full Professeur of (UIZ-FPO),
Winter term 2021/2022 Regression REG-11/55
Introduction
Solutions to Regression
Closed-Form Solutions and Normal Equation
Probabilistic Regression
Gradient Descent
Basis Function Regression
Wrap-Up
J(θ) = 1/2(X θ − y )⊺ (X θ − y )
= 1/2((X θ)⊺ − y ⊺ )(X θ − y )
= 1/2((X θ)⊺ X θ − (X θ)⊺ y − y ⊺ (X θ) + y ⊺ y )
= 1/2(θ ⊺ X ⊺ X θ − 2(X θ)⊺ y + y ⊺ y )
• To be continued...
L MOUATASIM
Abdelkrim E AI
Full Professeur of (UIZ-FPO),
Winter term 2021/2022 Regression REG-12/55
Introduction
Solutions to Regression
Closed-Form Solutions and Normal Equation
Probabilistic Regression
Gradient Descent
Basis Function Regression
Wrap-Up
!
∇θ J(θ) = 1/2(2X ⊺ X θ − 2X ⊺ y ) = 0
⇔ X ⊺X θ = X ⊺y
• If ⊺
X X is invertible, we can multiply both sides by (X ⊺ X )−1 :
Normal equation:
θ = (X ⊺ X )−1 X ⊺ y
L MOUATASIM
Abdelkrim E AI
Full Professeur of (UIZ-FPO),
Winter term 2021/2022 Regression REG-13/55
Introduction
Solutions to Regression
Closed-Form Solutions and Normal Equation
Probabilistic Regression
Gradient Descent
Basis Function Regression
Wrap-Up
Gradient Descent
• We want to minimize a smooth function J : Rm+1 → R:
min J(θ)
θ∈Rm+1
L MOUATASIM
Abdelkrim E AI
Full Professeur of (UIZ-FPO),
Winter term 2021/2022 Regression REG-15/55
Introduction
Solutions to Regression
Closed-Form Solutions and Normal Equation
Probabilistic Regression
Gradient Descent
Basis Function Regression
Wrap-Up
2
40
0
y
J(θ)
−2 y = θ0 + θ1 x 20
5
−4 0
−4 −2 0
−6 0
−6 −4 −2 0 2 4 6 2 4 θ1
x −5
θ0
L MOUATASIM
Abdelkrim E Full Professeur of AI
(UIZ-FPO),
Winter term 2021/2022 Regression REG-16/55
Introduction
Solutions to Regression
Closed-Form Solutions and Normal Equation
Probabilistic Regression
Gradient Descent
Basis Function Regression
Wrap-Up
L MOUATASIM
Abdelkrim E AI
Full Professeur of (UIZ-FPO),
Winter term 2021/2022 Regression REG-17/55
Introduction
Solutions to Regression
Closed-Form Solutions and Normal Equation
Probabilistic Regression
Gradient Descent
Basis Function Regression
Wrap-Up
L MOUATASIM
Abdelkrim E AI
Full Professeur of (UIZ-FPO),
Winter term 2021/2022 Regression REG-18/55
Introduction
Solutions to Regression
Closed-Form Solutions and Normal Equation
Probabilistic Regression
Gradient Descent
Basis Function Regression
Wrap-Up
J(θ) 40
20
5
0
−4 −2 0
0 2 4 −5 θ1
θ0
L MOUATASIM
Abdelkrim E Full Professeur of AI(UIZ-FPO),
Winter term 2021/2022 Regression REG-19/55
Introduction
Solutions to Regression
Closed-Form Solutions and Normal Equation
Probabilistic Regression
Gradient Descent
Basis Function Regression
Wrap-Up
X
n
min J(θ) = min ℓ(hθ (x (i) ), y (i) )
θ∈Rm+1 m+1 θ∈R
i=1
L MOUATASIM
Abdelkrim E Full Professeur ofAI (UIZ-FPO),
Winter term 2021/2022 Regression REG-21/55
Introduction
Solutions to Regression
Closed-Form Solutions and Normal Equation
Probabilistic Regression
Gradient Descent
Basis Function Regression
Wrap-Up
30 R (y )
• θ0 ≈ 7.4218
• θ1 ≈ 2.9827
20
• J(θ) ≈ 446.9584
• hθ (x ) = 7.4218 + 2.9827 · x1
10 • R = hθ (2.7) = 15.4750
M (x1 )
2 4 6 8
Abdelkrim EL MOUATASIM Full Professeur ofAI (UIZ-FPO),
Winter term 2021/2022 Regression REG-23/55
Introduction
Solutions to Regression
Closed-Form Solutions and Normal Equation
Probabilistic Regression
Gradient Descent
Basis Function Regression
Wrap-Up
2 Local
Global
J(θ)
Optimum
Optimum
0
−2 −1 0 1 2
θ
L MOUATASIM
Abdelkrim E AI
Full Professeur of (UIZ-FPO),
Winter term 2021/2022 Regression REG-24/55
Section:
Probabilistic Regression
Introduction
Solutions to Regression
Underlying Assumptions
Probabilistic Regression
Maximum Likelihood Solution
Basis Function Regression
Wrap-Up
Probabilistic Regression
w ≡θ
t≡y
y (x0 , w ) ≡ hθ (x0 )
• Given: A labeled set of training data points {(x (i) , y (i) )}ni=1
• Conditional likelihood (assuming the data is i. i. d.):
Y
n
p(y |X , θ, β) = N(y (i) |hθ (x (i) ), β−1 ) (15)
i=1
Y
n
= N(y (i) |θ ⊺ x (i) , β−1 ) (16)
i=1
L MOUATASIM
Abdelkrim E AI
Full Professeur of (UIZ-FPO),
Winter term 2021/2022 Regression REG-28/55
Introduction
Solutions to Regression
Underlying Assumptions
Probabilistic Regression
Maximum Likelihood Solution
Basis Function Regression
Wrap-Up
L MOUATASIM
Abdelkrim E AI
Full Professeur of (UIZ-FPO),
Winter term 2021/2022 Regression REG-29/55
Introduction
Solutions to Regression
Underlying Assumptions
Probabilistic Regression
Maximum Likelihood Solution
Basis Function Regression
Wrap-Up
∇θ log p(y |X , θ, β) = 0
X
n
−β (y (i) − θ ⊺ x (i) )x (i) = 0
i=1
...
θml = (X ⊺ X )−1 X ⊺ y
Minimizing the squared error gives the maximum likelihood solution for the
parameters θ assuming Gaussian noise.
Data
2
• So far we have tted straight lines
1
• What if the data is not
linear...? 0
y
1
The best-tting function is
obviously not a straight line! 2
L MOUATASIM
Abdelkrim E AI
Full Professeur of (UIZ-FPO),
Winter term 2021/2022 Regression REG-33/55
Introduction
General Idea
Solutions to Regression
Polynomial Basis Functions
Probabilistic Regression
Radial Basis Functions
Basis Function Regression
Regularization Techniques
Wrap-Up
Basis Functions
• Remember: `When stuck switch to a dierent perspective'
• We can add higher-order features using basis functions φ:
The model is still linear in the parameters, so we can still use the same algorithm
as before. This is still linear regression (!!!)
L MOUATASIM
Abdelkrim E Full Professeur ofAI (UIZ-FPO),
Winter term 2021/2022 Regression REG-35/55
Introduction
General Idea
Solutions to Regression
Polynomial Basis Functions
Probabilistic Regression
Radial Basis Functions
Basis Function Regression
Regularization Techniques
Wrap-Up
It is still linear!
L MOUATASIM
Abdelkrim E AI
Full Professeur of (UIZ-FPO),
Winter term 2021/2022 Regression REG-37/55
Introduction
General Idea
Solutions to Regression
Polynomial Basis Functions
Probabilistic Regression
Radial Basis Functions
Basis Function Regression
Regularization Techniques
Wrap-Up
L MOUATASIM
Abdelkrim E AI
Full Professeur of (UIZ-FPO),
Winter term 2021/2022 Regression REG-38/55
Introduction
General Idea
Solutions to Regression
Polynomial Basis Functions
Probabilistic Regression
Radial Basis Functions
Basis Function Regression
Regularization Techniques
Wrap-Up
L MOUATASIM
Abdelkrim E AI
Full Professeur of (UIZ-FPO),
Winter term 2021/2022 Regression REG-39/55
Introduction
General Idea
Solutions to Regression
Polynomial Basis Functions
Probabilistic Regression
Radial Basis Functions
Basis Function Regression
Regularization Techniques
Wrap-Up
Data
2
0
y
10 5 0 5 10
x
L MOUATASIM
Abdelkrim E AI
Full Professeur of (UIZ-FPO),
Winter term 2021/2022 Regression REG-40/55
Introduction
General Idea
Solutions to Regression
Polynomial Basis Functions
Probabilistic Regression
Radial Basis Functions
Basis Function Regression
Regularization Techniques
Wrap-Up
1 1
0 0
y
y
1 1
2 Data 2
Regression line
10 5 0 5 10 10 5 0 5 10
x x
• Undertting
• The model is not complex enough to t the data well ⇒ High bias
• Make the model more complex; adding new examples does not help
• Overtting
• The model predicts the training data perfectly
• But it fails to generalize to unseen instances ⇒ High variance
• Decrease the degree of freedom or add more training examples
• Also: Try regularization
• Bias-Variance trade-o
L MOUATASIM
Abdelkrim E AI
Full Professeur of (UIZ-FPO),
Winter term 2021/2022 Regression REG-42/55
Introduction
General Idea
Solutions to Regression
Polynomial Basis Functions
Probabilistic Regression
Radial Basis Functions
Basis Function Regression
Regularization Techniques
Wrap-Up
Data
2 Regression line
0
y
10 5 0 5 10
x
L MOUATASIM
Abdelkrim E Full Professeur ofAI (UIZ-FPO),
Winter term 2021/2022 Regression REG-43/55
Introduction
General Idea
Solutions to Regression
Polynomial Basis Functions
Probabilistic Regression
Radial Basis Functions
Basis Function Regression
Regularization Techniques
Wrap-Up
X
m X
m
|θ| = |θj | ∥θ∥2 = θ2j
j=1 j=1
Regularization visualized
• Here: w ≡ θ
• L1-Regularization
⇒ Lasso regression
(least abs. shrinkage and select. operator)
• L2-Regularization
⇒ Ridge regression
(Tikhonov regularization)
• The combination of both is called
elastic net cf. [1], p. 146; left: L2, right: L1
Incorporating Regularization
The regularization also
• Normal equation with regularization: helps to overcome numerical issues!
(ridge regression)
θ = (X ⊺ X + λI )−1 X ⊺ y (25)
• Regularized gradient descent update rule:
1 1
0 0
y
y
1 1
2 Data
Regression line 2
10 5 0 5 10 10 5 0 5 10
x x
Summary
• Regression predicts continuous target variables
• The algorithm minimizes the (mean) squared error
• Minimizing the squared error gives the maximum likelihood solution
• Two approaches:
1 Normal equation
2 (Batch / stochastic / mini-batch) gradient descent
• Probabilistic regression allows to quantify the uncertainty of the model
• Use basis functions to t non-linear regression lines
• Regularization is important
L MOUATASIM
Abdelkrim E AI
Full Professeur of (UIZ-FPO),
Winter term 2021/2022 Regression REG-49/55
Introduction Summary
Solutions to Regression Self-Test Questions
Probabilistic Regression Lecture Outlook
Basis Function Regression Recommended Literature and further Reading
Wrap-Up Meme of the Day
Self-Test Questions
What's next...?
L MOUATASIM
Abdelkrim E AI
Full Professeur of (UIZ-FPO),
Winter term 2021/2022 Regression REG-51/55
Introduction Summary
Solutions to Regression Self-Test Questions
Probabilistic Regression Lecture Outlook
Basis Function Regression Recommended Literature and further Reading
Wrap-Up Meme of the Day
→ Link
L MOUATASIM
Abdelkrim E AI
Full Professeur of (UIZ-FPO),
Winter term 2021/2022 Regression REG-52/55
Introduction Summary
Solutions to Regression Self-Test Questions
Probabilistic Regression Lecture Outlook
Basis Function Regression Recommended Literature and further Reading
Wrap-Up Meme of the Day
→ Link
L MOUATASIM
Abdelkrim E AI
Full Professeur of (UIZ-FPO),
Winter term 2021/2022 Regression REG-53/55
Introduction Summary
Solutions to Regression Self-Test Questions
Probabilistic Regression Lecture Outlook
Basis Function Regression Recommended Literature and further Reading
Wrap-Up Meme of the Day
L MOUATASIM
Abdelkrim E AI
Full Professeur of (UIZ-FPO),
Winter term 2021/2022 Regression REG-54/55
Thank you very much for the attention!