Linear Regression
Linear Regression
no ok
yes
+line of regression
• Equation Y=a0+a1X
• Negative Linear Relationship:
If the dependent variable decreases on the Y-axis
and independent variable increases on the X-axis,
then such a relationship is called a negative linear
relationship.
• Equation Y=-a0+a1x
Y
- ve line of regression
y
• Finding the best fit line:
• When working with linear regression, our main goal is
to find the best fit line that means the error between
predicted values and actual values should be
minimized. The best fit line will have the least error.
• The different values for weights or the coefficient of
lines (a0, a1) gives a different line of regression, so we
need to calculate the best values for a0 and a1 to find
the best fit line, so to calculate this we use cost
function.
• Cost function-
• The different values for weights or coefficient of
lines (a0, a1) gives the different line of regression,
and the cost function is used to estimate the
values of the coefficient for the best fit line.
• For Linear Regression, we use the Mean Squared
Error (MSE) cost function, which is the average
of squared error occurred between the predicted
values and actual values. It can be written as:
example
s.no Age (X) Glucose levels (Y)
1 43 99
2 21 65
3 25 79
4 42 75
5 57 87
6 59 81
7 55 ?
• Equation Y=a0+a1X
• A0=(Σy)(Σx²)-(Σx)(Σxy)
n(Σx²)-(Σx)²
• A1=n(Σxy)-(Σx)(Σy)
n(Σx²)-(Σx)²
s.No Age (X) Glucose level XY x²
(Y)
1 43 99 4257 9801
2 21 65 1365 4225
3 25 79 1975 6241
4 42 75 3150 5625
5 57 87 4959 7569
6 59 81 4779 6561
247 486 20485 40022
• Step 2 :
• a0=65.14
• a1=0.385335
• Step 3: insert the values in the equation
• Y=65.14+0.385335 X
• Step 4: predict the value of Y for the given value of X=55
• Y=65.14+0.385335 * 55
• Y=86.327
• Hence the glucose level for the given age 55 is 86.327