You are on page 1of 11

Machine Learning

- Presented by
Mr. P. MEENATCHISUNDARAM
Lesson 2

Linear Regression

2
Linear Algorithms
Models based on linear regression are called Linear
Algorithms. Some of the Linear Algorithms are:

Gradient Descent Algorithm

Stochastic Gradient Descent Algorithm

Logistic Regression

Linear Discriminant Analysis

3
Linear regression Models
Many simple models follow linear regression
• y = B0 + B1 x [y=mx+c]
• The model that follows linear equation
Making Predictions with Linear Regression
• Imagine we are predicting weight (y) from height (x).
• y = B0 + B1 X1
weight = B0 + B1 × height
• Where B0 is the bias coefficient and
• B1 is the coefficient for the height column.

4
Simple Linear Regression
For example, let’s use B0 = 0.1 and B1 = 0.5. Let’s
plug them in and calculate the weight (in kilograms)
for a person with the height of 182 centimeters.
• weight = 0.1 + 0.5 × 182 weight = 91.1

5
Tutorial for Linear Regression
Using Tutorial Data Set Find Bo and B1
X 1 2 4 3 5
Y 1 3 3 2 5

Bo = 0.4 and B1 = 0.8


6
Alternate Method
• Pearson Correlation Coefficient :
If r- is positive, x & y have
positive linear
relationship
If r- is negative, x & y
have negative linear
relationship
If r =0 – No relationship
Use Pearson in Excel
Standard Deviation:
To Calculate B1

7
Estimating the Slope and Intercept (B1, B0)

• X 1 2 4 3 5 Xmean = 3

Y 1 3 3 2 5 Ymean =2.8
(X-Xmean)^2
X-Xmean -2 -1 1 0 2 = 10

Y-Ymean -1.8 0.2 0.2 -0.8 2.2


(X-Xmean) X
(Y-Ymean) 3.6 -0.2 0.2 0 4.4 Sum =8
B1 8/10 = 0.8

B0 = Ymean – B1(Xmean) = 2.8 – 0.8( 3) = 0.4


Example of Linear Regression
8
Root Mean Square Error (RMSE)
Assumed Model: y = B0 + B1 x
Predicted Values: B0 = 0.4; B1=0.8
X 1 2 4 3 5
Y 1 3 3 2 5
YP 1.2 2 3.6 2.8 4.4
Error -0.2 1 -0.6 -0.8 0.6
(Y – YP)

By Calculation:
RMSE = 0.6928

9
Linear Regression
Exercise 1
Data Set
X 5 7 9 12 15
Y 26 32 40 54 64

i) Find the Coefficients of B0 and B1 and plot the


predicted values and the given values
ii) Find the Pearson Correlation Coefficient and
interpret the linear relationship of the data
iii) Using Pearson Correlation Coefficient find B0 & B1
iv) Find Root Mean Squared Error (RMSE)
v) When X=18 find out the value of ‘Y’?

10
An Error is not a Mistake until you
refuse to correct it.

Yes, We want to reduce errors


_______________
Let us correct our errors!

11

You might also like