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 = \frac{(\Sigma y)(\Sigma x^2) - (\Sigma x)(\Sigma xy)}{n(\Sigma x^2)-(\Sigma x)^2}\]
\[b = \frac{n\Sigma xy - (\Sigma x)(\Sigma y)}{n(\Sigma x^2)-(\Sigma x)^2}\]

Then
x
y
$x^2$
xy
$y^2$
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 = \frac{(40 \times 524) - (56 \times 364)}{(8 \times 524) - (56)^2 } = 0.545$

$b =\frac{(8\times 364)-(56\times 40)}{(8\times 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