Processing math: 100%

Pages

Linear Regression Example


Let’s assume that we are given data with x values and their labels y.
x
Y
1
1
3
2
4
4
6
4
8
5
9
7
11
8
14
9

Now to find the line that fits best with the least square method, we simply need to find the parameters like slope and the intercept of the line i.e m and c.
Let equation of line be          y = bx + a
Where b is the slope and a is intercept which is given by
a=(Σy)(Σx2)−(Σx)(Σxy)n(Σx2)−(Σx)2
b=nΣxy−(Σx)(Σy)n(Σx2)−(Σx)2

Then
x
y
x2
xy
y2
1
1
1
1
1
3
2
9
6
4
4
4
16
16
16
6
4
36
24
16
8
5
64
40
25
9
7
81
63
49
11
8
121
88
64
14
9
196
126
81
Sum = 56
Sum = 40
Sum  = 524
Sum = 364
Sum = 256

Now 
a=(40Ă—524)−(56Ă—364)(8Ă—524)−(56)2=0.545

b=(8Ă—364)−(56Ă—40)(8Ă—524)−(56)2=0.636

So equation of the line will be  y=0.636x+0.545

No comments:

Post a Comment

If you have any doubt, let me know

Email Subscription

Enter your email address:

Delivered by FeedBurner

INSTAGRAM FEED