0% found this document useful (0 votes)
29 views4 pages

Iml Exp. 3

m

Uploaded by

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

Iml Exp. 3

m

Uploaded by

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

Experiment 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.

xLinear Regression is of two types: Simple and Multiple.


a) Simple Linear Regression is where only one independent variable is present and the
model has to find the linear relationship of it with the dependent variable.
b) In Multiple Linear Regression there are more than one independent variable present
for the modelto find the relationship.

Equation of Simple Linear Regression:

=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.

Draw this figure and below text on white page

30
Regression line
25

> 20

15

~error term (e)


10
b0

100 200 300

" 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.

Example: (Draw this table on white page)


AGE (X) GLUCOSE LEVEL (Y) XY
SUBJECT

1 43 99 4257 1849 9801

2 21 65 1365 441 4225

3 25 79 1975 625 6241

42 75 3150 1764 5625

57 87 4959 3249 7569

6 59 81 4779 3481 6561

247 486 20485 11409 40022

Write all these steps onruled page


Step 1: Find bo:

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

y'= 65.14 + (0.385225 * x)


Step 4: Prediction - the value of y for the given value
ofx = 55

y'= 65.14 +(0.385225 *55)


y' =86.327
Code (Part Iand Part ): (on ruled page)
Code Output and below graph: (on white page)

Age Vs Glucose Level


110

100

90

80

70

60

50

40

30

20

10
10 20 30 40 50 60 7
Age

You might also like