2 Simple Linear Regression
2 Simple Linear Regression
• Classification Problems
• Prediction of cancer
• Win prediction of Sh. Narendra Modi ji
• Diabetic Prediction
• Classification of e-mail
Dr. Shweta Sharma, Dept. of CSE, PEC Chandigarh 4
Understand the Data……..
7
Linear Regression
A statistical method that is used for predictive analysis
Makes predictions for continuous/real or numeric variables such as sales, salary,
age, product price, etc.
Since linear regression shows the linear relationship, which means it finds how
the value of the dependent variable is changing according to the value of the
independent variable Dr. Shweta Sharma, Dept. of CSE, PEC Chandigarh 8
Linear regression performs the task to predict a
dependent variable value (y) based on a given
independent variable (x)
If there is a single input variable (x), such linear regression is called simple linear regression
y= b*x+a
or
y= a0+a1*x
• Y= Dependent Variable (Target Variable) (ESTIMATED OUTPUT)
• X= Independent Variable (predictor Variable) (INPUT)
• a0= Intercept of the line (Gives an additional degree of freedom) (regression coefficient)
• a1 = Linear regression coefficient (scale factor to each input value) (SLOPE) (regression coefficient)
The motive of the linear regression algorithm is to find the best values for a_0 and a_1
X: amount of fertilizer, y: size of crop (every time we add a unit to X, the dep variable y increases
Dr. Shweta Sharma, Dept. of CSE, PEC Chandigarh 10
proportionally)
Multiple Linear Regression
If there is more than one input variable, such linear regression is called multiple linear
regression
y= a + b_1*x_1 + b_2*x_2 + b_3*x_3+… + b_n*x_n
or
y= a_0 + a_1*x_1 + a_2*x_2+.. + a_n*x_n
Eg: Add amount of sunlight and rainfall in a growing season to the fertilizer variable, with all 3
affecting y
This provides the average squared error over all the data points. Therefore, this cost function is also known as
the Mean Squared Error (MSE) function
Now, using this MSE function we are going to change the values of a_0 and a_1 such that the MSE value settles
at the minima Dr. Shweta Sharma, Dept. of CSE, PEC Chandigarh 15
Linear regression: A sample curve-fitting
• Y = m*x + b
• Method of least
square
• Gradient descent
approach
16
Ordinary Least Squares (OLS) Method
y= m*x+b
• Gradient descent is a method of updating a_0 and a_1 to reduce the cost function (MSE)
• The idea is that we start with some values for a_0 and a_1 and then we change these
values iteratively to reduce the cost
To find these gradients, we take partial derivatives with respect to a_0 and a_1
The partial derivates are the gradients and they are used to update the values of
a_0 and a_1
Alpha is the learning rate which is a hyper-parameter that you must specify
A smaller learning rate could get you closer to the minima but takes more time to
reach the minima, a larger learning rate converges sooner but there is a chance
that you could overshoot the minima
22