Iml Exp. 3
Iml Exp. 3
Vobjective: Write a program to obtain the least square regression line to best fit the given data
for any linear regression problem. Also, predict the output for the test datasets and determine
the accuracy sCore.
Vtheory:
Linear Regression is the supervised Machine Learning model in which the model finds the best
fit linear line between the independent and dependent variable i.e it finds the linear
relationship between the dependent and independent variable.
=b, + b,x
where, bo is the intercept, b1 is coefficient or slope, x is the independent variable, andy is the
dependent variable.
bo =
(y) (2x) (Zx)(2xy)
n(x?) - (x)2
Wbi = nn(Jx?)
()xy) -(x)(Ly)
- (x)2
A Linear Regression model's main aim is to find the best fit linear line and the optimal values of
intercept and coefficients such that the error is minimized.
Error is the difference between the 'Actual value' and 'Predicted value' and the goal is to
reduce this difference. The vertical distance between the data point and the regression line is
known as error or residual. Each data point has one residual and the sum of all the differences is
known as the Sum of Residuals/Errors.
Mathematical Approach:
Residual/Error = Actual values - Predicted Values
Sum of Residuals/Errors =Sum(Actual- Predicted Values)
Square of Sum of Residuals/Errors =(Sum(Actual- Predicted Values)2
ie.
30
Regression line
25
> 20
15
" x is our dependent variable which is plotted on the xaxis and y is the dependent
variable which is plotted on the y-axis.
Black dots are the data points i.e the actual values.
bo is the intercept which is 10 and b1 is the slope of thexvariable.
The blue line is the best fit line predicted by the model i.e the predicted values lie on
the blue line.
bÍ =
(Ey)(2x*) - (Zx)(xy)
n(x2) - (x)?
(486) (11409) - (247) (20485)
bo =
6(11409) (247)2
4848979
bÍ = = 65.14
7445
Step 2: Find b1:
b, =
n(Exy)-(Z:)(Ly)
n(x?) - (x)?
6 (20485) - (247) (486)
bË =
6(11409) - (247)2
2868
b, = = 0.385335
7445
Step 3: Insert the values into the equation
y' =bo +b1 *x
100
90
80
70
60
50
40
30
20
10
10 20 30 40 50 60 7
Age