Lecture 3 Multi-Regresion 2022.
Lecture 3 Multi-Regresion 2022.
1
Outline
• Simple Linear Regression
• Multivariate Linear Regression
• Basis Function Regression
• Regularization
2
Simple Linear Regression
3
Simple Linear Regression
Dependent Variable : Play? Dependent Variable : Play?
Weather outlook Weather outlook
Humidity Humidity
Windy Windy
<=70 >70 True False <=70 >70 True False
Play:3 Play:0 Play:0 Play:3 Play~=30 min Play~=5min Play ~=0 min Play ~=32 min
Don’t Play: 0 Don’t Play: 3 Don’t Play: 2 Don’t Play: 0
Play =30 min ,45 min Play =0 min ,0 min, Play =0 min ,0 min Play=20 min , 30 min
15 min , 45 min
Decision Tree Classification Regression Tree
4
𝑦! = 𝑤𝑥! + 𝜀!
𝜀! = 𝑦! − 𝑤𝑥!
If there is N sample, there will be N number of 𝜀 from 𝜀" , 𝜀# ⋯ 𝜀$
𝑦 = 𝑤𝑥 + 𝜀 noise 𝑦 = 𝑤𝑥 + 𝜀
∑%
"#$ 𝑥" 𝑦" 𝑐𝑜𝑣(𝑥, 𝑦)
𝑤= = if mean of 𝑥 and 𝑦 are 0
∑%"#$ 𝑥"
& 𝑣𝑎𝑟(𝑥)
E
+, +,
<0
• Total square sum of error E = ∑0
!./ 𝜀! 1 = ∑0
!./ 𝑦! − 𝑤𝑥! 1. +- +, +-
>0
+-
=0
• To get minimum error, %
&
𝑤 = arg m𝑖𝑛 - 𝑦" − 𝑤𝑥"
! weight
"#$
,
• To obtain 𝑤, differentiate wrt to 𝑤 → ,- ∑0
!./ 𝑦! − 𝑤𝑥!
1 =0
0 0 0 0 0
, 1
,-
∑0
!./ 𝑦! − 𝑤𝑥!
1 = 0 → 2 E −𝑥! 𝑦! − 𝑤𝑥! = 0 → E 𝑥! 𝑦! − E 𝑤𝑥! 1 = 0 → E 𝑤𝑥! = E 𝑥! 𝑦!
!./ !./ !./ !./ !./
∑0
!./ 𝑥! 𝑦!
→𝑤= 0
∑!./ 𝑥! 1
Simple Linear Regression
• Accuracy of prediction
• Root mean square Error (RMS)
$ $
RMS error = ∑% 𝜀 & = ∑%
"#$ 𝑦" − 𝑦
/" &
% "#$ " %
&
∑%
"#$ 𝑦" − 𝑦
/" &
Variance of the model errors
𝑅 =1− %
∑"#$ 𝑦" − 𝑦B &
Variance of the data
where 𝑦B is the mean of 𝑦
8
• The more accurate the prediction is, 𝑅& → 1
Multivariate Linear Regression (MLR)
• Multiplevariate (input) regression
• E.g. Predict Google’s stock price using Yahoo, Microsoft , Ebay, Amazon
Google Stock Yahoo Stock Microsoft stock Ebay stock Amazon stock
𝑦 = - 𝑤0 𝜙0 (𝑥) + 𝜀
0#' 50 points of 𝑦 = 𝑠𝑖𝑛𝑥 corrupted by gaussian
noise. Fit with a gaussian function
where 𝜙0 𝑥 can be either 𝑥0 or one of the above non-linear basis
11
function. 𝜙' 𝑥 = 1 for the intercept term
Basis Function Regression
• Using the same least square approach, task is to predict for 𝑁 sample of training data of 𝑦F!
G/, 𝑦G1 ⋯ 𝑦G0 where 𝑦F! = ∑5 𝑤4 𝜙4 (𝑥 ! ) by minimizing the error or loss function
from 𝑦 4.+
&
% % *
&
𝐽(𝒘) = - 𝑦 " − 𝑦_" = - 𝑦 " − - 𝑤0 𝜙0 (𝑥 " )
"#$ "#$ 0#'
50 points of 𝑦 = 𝑠𝑖𝑛𝑥 corrupted by 50 points of 𝑦 = 𝑠𝑖𝑛𝑥 corrupted by 50 points of 𝑦 = 𝑠𝑖𝑛𝑥 corrupted by 50 points of 𝑦 = 𝑠𝑖𝑛𝑥 corrupted
gaussian noise. Fit with a polynomial gaussian noise. Fit with a polynomial gaussian noise. Fit with a polynomial by gaussian noise. Fit with a
function of order 1. function of order 3. function of order 7. polynomial function of order 20.
𝑤! = −0.012 , 𝑤" = 0.348 𝑤! = −0.721 , 𝑤# = 0.141 , 𝑤$ = −0.008,
𝑤" = 1.089 13
Regression Model Overfitting
• Regularization
• a regulated process applied to the linear model by minimizing the
least square loss function with a penalty function
50 points of 𝑦 = 𝑠𝑖𝑛𝑥 corrupted
• Ridge Regression (𝐿& Regulation) by gaussian noise. Fit with a
• A form of MLR that penalize the sum of squares of the model polynomial function of order 20.
coefficients
%
&
𝐽(𝒘) = - 𝑦" − 𝑦/" +𝑃 Penalty function
"#$
Penalty function
#UofGWorldChangers
@UofGlasgow
16