0% found this document useful (0 votes)
6 views14 pages

Linear Regression Exampl;e

Uploaded by

Saranya Sarkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views14 pages

Linear Regression Exampl;e

Uploaded by

Saranya Sarkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Linear Regression

Linear Regression Example


• +x+ϵ
• intercept ( Bias)
• Slope
• ϵ error in the prediction.
Assumption of Linear Regression
• 1) y is random & mutually independent
• 2) ϵ =
• = Predicted output
• = True output
Linear Regression Example

e3

e1
e2
• + )+
• + )+

•.
• + )+

• = - + )

• <, , …… , > are errors detailed


• E= = )
• As the minmisation of sum of absolute values of individual errors
• E= = )
• E= =
• Or sum of square
•E= =
• So, Linear regression is modelled as a minimization function as follows
• J(a, b) =
• F) =
• Criteria function of parameter & . These need to be minimized.
• Solution
• Differentiate and zero
• Differentiate and zero
Xi (Week) Yi (Solution)
• = 1 1.2
• =- 2 1.8
3 2.6
4 3.2
Xi Yi X
(Week) (Solution) 5 3.8
1 1.2 1 1.2
2 1.8 4 3.6
3 2.6 9 7.8
= = 0.66
4 3.2 16 12.8
= 2.52 -0.66X3 = 0.54
5 3.8 25 19
Y= 0.54+0.66 X x
Sum=15 Sum=12.6 Sum=55 Sum= 44.4
= 15/5 = 12.6/5 = = 44.5/5 For x=7
=3 =2.52 55/5=11 8.88 = 5.16
Linear Regression in Matrix
From
• = +

• Y = Xa + e,
• X = nX2
• Y = nX1
Xi (Week) Yi (Prod Sales)
• A= 2X1
1 1
• e = nX1 2 3
3 4
4 8
𝑋 =[ 1 23 4 ] ,𝑌 =[ 1 3 4 8 ]
𝑡 𝑡

( ) ()
1 1 1
𝑋= 1
2 Find linear regression𝑌equation
=
3 for the following
1 3 two sets of data: 4
1 4 8

a= ( ሺ (𝑿𝒕 𝑿ሻ −𝟏 𝑿𝒕) 𝒀

After Calculating a,
a0 = Intercept = -1.5000
a1 = Slope = 2.2000
>> X'*X >> inv(X'*X)*X'
ans = ans =
4 10 1.0000 0.5000 0 -
0.5000
10 30
-0.3000 -0.1000 0.1000
>> inv(X'*X) 0.3000
ans =
1.5000 -0.5000 >> (inv(X'*X)*X')*Y
ans =
-0.5000 0.2000
-1.5000
After calculating a, 2.2000
a0 = Intercept = -1.5000
a1 = Slope = 2.2000
Y= -1.5 + 2.2X
xi yi

Validation of Regression Model I1


I2
80
90
I3 100
a) MAE= I4 110
• = actual, I5 120
b) MSEtrain =
• Root Mean Square Error RMSE Let I6 & I7 – Actual values are 80 & 75
c) RMSE = Regression Predicts – 75 & 85
d) Relative MSE yi
• RelMSE = I6 80 75
0 – Model is perfect and its value
between 0 to 1 I7 75 85
1 not good = (80+90+100+110+120)/5 = 100
e) Coeff of CV RelMSE =
CV = .08
CV=
xi yi

Validation of Regression Model I1


I2
80
90
I3 100
a) MAE= I4 110
• = actual, I5 120
b) MSEtrain =
• Root Mean Square Error RMSE Let I6 & I7 – Actual values are 80 & 75
c) RMSE = Regression Predicts – 75 & 85
d) Relative MSE yi
• RelMSE = I6 80 75
0 – Model is perfect and its value
between 0 to 1 I7 75 85
1 not good MAE = ½ * ( |80-75| + |75-85|) = 15/2 = 7.5
e) Coeff of CV MSE = 62.5
CV= RMSE = sqrt(62.5) = 7.91
Validation of Regression Model
Coeff of determination Standard Error Estimation:

=
SStot =

1 to inf
Multiple Linear Regression
• Y= f(x1,x2)
= + + + …. + + ϵ
Where (, ……., ) are independent variables
Y is dependent
(, …… – Coef of regression coefficient
x1 x2 yi
1 4 1
2 5 6
3 8 8
4 2 12

X=
1 1 4
1 2 5 >> a= (inv(X'*X)*X')*Y
1 3 8
1 4 2 a=

>> Y= [1 6 8 12]' -1.6995


Y= 3.4836
1 -0.0546
6
8
12

You might also like