ML Unit2
ML Unit2
LEARNING
UNIT-2
Unit-2
• Linear regression analysis is used to predict the value of a variable based on the
value of another variable.
• The variable you want to predict is called the dependent variable. The
variable you are using to predict the other variable's value is called the
independent variable.
• Linear regression is a supervised machine learning model majorly used in
forecasting. Supervised machine learning models are those where we use the
training data to build the model and then test the accuracy of the model using
the loss function.
• As the name suggests, it assumes a linear relationship between a set of
independent variables to that of the dependent variable (the variable of interest).
A LINE OF
LINEAR
REGRESSION
○ 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.
○ Cost function optimizes the regression coefficients or weights. It measures
how a linear regression model is performing.
○ We can use the cost function to find the accuracy of the mapping function,
which maps the input variable to the output variable. This mapping function is
also known as Hypothesis function.
The cost function used in linear regression are
• Mean Squared error(MSE)
Gradient Descent
○ Gradient descent is used to minimize the MSE by
calculating the gradient of the cost function.
○ A regression model uses gradient descent to update the
coefficients of the line by reducing the cost function.
○ It is done by a random selection of values of coefficient
and then iteratively update the values to reach the
minimum cost function.
Multiple linear regression
y = f(x1,x2)
y = ao+a1x1+a2x2
• Similarly,for a given ‘n’ independent variables,the equation is
y = f(x1,x2,..xn)
y = ao+a1x1+a2x2+..+anxn+ε
X1 X2 Y
- - - ● Apply multiple Regression
Product Product Weekly
for the values given in Table
1 Sales 2 sales sales
where weekly sales along
1 4 1 with sales for products x1
2 5 6 and x2 are provided
3 8 8 ● Matrix approach is used to
solve the problem
4 2 12
X1 X2 Y X= 1 1 4
1
- - - 1 2 5 Y= 6
1 3 8
Product 1 Product 2 Weekly 1 4 2
8
12
Sales sales sales CO
1 4 1 B I L1
AS - – X2
L 3
2 5 6 CO
3 8 8 COL2-X1
4 2 12
• The coefficient of multiple linear regression equation is
a0
a= a1
a2
A
Now calculate
1 1 1 1
(X X) X =
T -1 T
A * 1 2 3 4
4 5 8 2
a1 a0
a2
y=a0+a1x1+a2x2
y=-1.69+3.48x1-0.05x2
• The student dataset has entrance marks based on the historic data of those who are
Based on the logistic regression ,the values of the learnt parameters are 𝜷0=1 and
selected or not selected
•
𝜷1=8
• Assume the marks of X=60 and threshold value=0.5,compute the resultant class
p(x)=1/(1+e-(𝜷0+𝜷1x))
𝜷0+𝜷1x=481 where
𝜷0=1,𝜷1=8,x=60
p(x)=1/(1+e-481) =0.44
• 0.44<0.5 ,therefore for the given marks the student will come under the class “NOT
SELECTED”
Logistic Regression example