Unit-02 - Supervised Machine Learning
Unit-02 - Supervised Machine Learning
Unit 02
Supervised Learning: Regression
1
2/27/2026
Linear regression
Linear Regression:
a statistical approach to modeling the relationship
between a dependent variable and a given set of
independent variables
Linear regression
Linear Regression:
There is a non-linear
correlation when there is a
relationship between variables
but the relationship is
not linear (straight)
2
2/27/2026
3
2/27/2026
4
2/27/2026
y = a0 + a1X
Where,
y: Predicted value
a0: Y- intersect
a1 : Slope of independent variable
X : Independent variable
5
2/27/2026
6
2/27/2026
7
2/27/2026
Where,
Xi: ‘i‘ th input variable
yi: ‘i‘ th onput variable
x̅ : Mean of all X values
y̅ : Mean of all y values
R. B. Mannade, Asst. Professor Govt. College of Engineering, Aurangabad(MS) | 15
a1
a0 = y̅ - a1x͞
8
2/27/2026
9
2/27/2026
2004 3445.67
10
2/27/2026
11
2/27/2026
F4: Condition of
the house
F5: Price of
House ? Dependent Variable
y = a0+a1x1+a2x2+a3x3+ …… anxn + є
Where,
a0 : ‘y’ Intercept
a1 , a2 , a3 , … an : Slope or Coefficient of regression
x1 , x2 , x3 , … xn : Independent / Predictor variables
Є : Error
12
2/27/2026
F2: No. of
Bedrooms
F3: Locality
F4: Condition of
the house Price of House =
F5: Price of a0 + a1(Size of the house) + a2(No.
House ? of Bed rooms) + a3(Locality) +
a4(Condition of the house)
13
2/27/2026
3 8 8
4 2 12
6 10 ?
Bias Intersect
Coeff. Of
Equation of Y-Intersect and Slopes will be TV
as: Coeff. Of
Mobile
2 5 6
3 8 8
4 2 12
6 10 ?
14
2/27/2026
2 5 6
3 8 8
4 2 12
6 10 ?
2 5 6
3 8 8
4 2 12
6 10 ?
15
2/27/2026
2 5 6
3 8 8
4 2 12
6 10 ?
Intersect
Coeff. Of
TV
Coeff. Of
Mobile
Weekly Sales = 2 5 6
-1.69+3.48(TV) - 0.05(Mobile) 3 8 8
4 2 12
= -1.69+3.48(6) - 0.05(10) 6 10 ?
= 18.69
16
2/27/2026
Squaring makes all errors positive and penalizes large mistakes more than
small ones
For example, being wrong by 10 (error² = 100) is much worse than being
wrong by 2 (error² = 4)
R. B. Mannade, Asst. Professor Govt. College of Engineering, Aurangabad(MS) | 34
17
2/27/2026
18
2/27/2026
19
2/27/2026
20
2/27/2026
21
2/27/2026
22
2/27/2026
23
2/27/2026
24
2/27/2026
25
2/27/2026
26
2/27/2026
27
2/27/2026
28
2/27/2026
80 75
60 70
90 85
70 65
85 95
29
2/27/2026
30
2/27/2026
MAE = 35/5 = 7
Interpretation:
Since, MSE is lower this
model is a average model
R. B. Mannade, Asst. Professor Govt. College of Engineering, Aurangabad(MS) | 61
31
2/27/2026
R² (R-squared) - Coefficient of
Determination
32
2/27/2026
33
2/27/2026
34
2/27/2026
35
2/27/2026
36
2/27/2026
37
2/27/2026
Interpreting R-Squared:
A high R2 means the model explains a large portion of
the variance. However, it doesn’t mean our model is
necessarily correct or useful
A low R-squared means little variance is explained by
the model. This isn’t always bad
Especially in social sciences or noisy data, where a low
R-squared is often expected
R. B. Mannade, Asst. Professor Govt. College of Engineering, Aurangabad(MS) | 76
38
2/27/2026
39
2/27/2026
Logistic Regression
Logistic regression
40
2/27/2026
Logistic regression
Scenarios of predicting categorical variables:
1. Is email Spam or not? Answer: Yes or No ⇨ Categorical
response
Logistic regression
How Logistic regression works?
Suppose, a company wants to
determine employee’s salary hike
based on their performance
Salary Hike
41
2/27/2026
Logistic regression
How Logistic regression works?
Suppose, a company wants to
determine employee’s salary hike
based on their performance
Salary Hike
Linear regression model will solve
this problem
Independent variable: Employees
performance rating, Dependent
Variable: Salary hike
Plotting a best-fit regression line
will serve the purpose Employee Rating
Logistic regression
How Logistic regression works?
What if, a company wants to know
whether employee should be get
promotion or not?
Salary Hike
Employee Rating
42
2/27/2026
Logistic regression
How Logistic regression works?
What if, a company wants to know
whether employee should be get
promotion or not?
getting promotion
Probability of
Linear regression model wont
solve this problem
Instead of straight line, S- shaped
curve is fitted over data points
If probability is 0 ⇨ Wont get
promotion
If probability is 1 ⇨ Get promotion Employee Rating
Logistic regression
How Logistic regression works?
But probability is not always 0 or 1
What if it is between these two?
A threshold value is decided
getting promotion
Probability of
43
2/27/2026
Logistic regression
How Logistic regression
works?
Suppose employee rating is 2.8,
getting promotion
probability = 0.25 ⇒ wont get
Probability of
promotion
Logistic regression
Logistic Function (Sigmoid
Function):
A mathematical function used to
map the predicted values to
probabilities
It maps any real value into another
value within a range of 0 and 1
Values above the threshold value
tends to 1, and a value below the
threshold values tends to 0
Values is equal to exactly 0.5, value
tends to 1
R. B. Mannade, Asst. Professor Govt. College of Engineering, Aurangabad(MS) | 88
44
2/27/2026
Logistic regression
Assumptions of Logistic Regression:
Independent observations: Each observation is independent of
the other. meaning there is no correlation between any input
variables.
Binary dependent variables: The dependent variable must be
binary or meaning it can take only two values.
Linear relationship between independent variables and log
odds
No outliers: There should be no outliers in the dataset.
Large sample size: The sample size is sufficiently large
R. B. Mannade, Asst. Professor Govt. College of Engineering, Aurangabad(MS) | 89
Logistic regression
Equation of Logistic regression: y
Odds of success:
a1
a0
x
Values of Odds ranges form 0 to ∞, as P can
be between 0 and 1
Consider the equation straight line:
y=a0+a1.x
R. B. Mannade, Asst. Professor Govt. College of Engineering, Aurangabad(MS) | 90
45
2/27/2026
Logistic regression
Equation of Logistic regression: y
To find out Odds of success we need to take
logarithm of : i.e.
a1
Here, P is x, as we want the probability of
happening of x then its corresponding y
a0
value. Hence equation becomes:
x
Logistic regression
Equation of Logistic regression:
46
2/27/2026
Logistic regression
=1
=1
Logistic regression
Numerical Example 1:
Consider a dataset of CIBIL
scores of the bank customers.
A trained logistic regression
model have learned the
parameters as: a0 = 1 and a1 =
8.
If a customer XYZ has a CIBIL
score of 60, predict whether
he/she will get a loan or not.
(Assume a threshold of 0.5) Since, probability of getting a loan is 1
(above threshold value), a customer
will get a loan
R. B. Mannade, Asst. Professor Govt. College of Engineering, Aurangabad(MS) | 94
47
2/27/2026
Logistic regression
Numerical Example 2: Study Hours Pass(1)/Fail(0)
Consider a dataset that contains hours 29 0
of study and result of student. Apply 15 0
Logistic regression classifier and
33 1
answer the following questions:
28 1
1. What is probability of student to
pass who studied for 33 hours? 39 1
Logistic regression
In logistic regression sigmoid curve is given by:
48
2/27/2026
Logistic regression
Numerical Example 2: Study Hours Pass(1)/Fail(0)
1. What is probability of student to pass who 29 0
studied for 33 hours? 15 0
33 1
28 1
39 1
Logistic regression
Numerical Example 2: Study Hours Pass(1)/Fail(0)
1. What is probability of student to pass who 29 0
studied for 33 hours? 15 0
33 1
28 1
39 1
49
2/27/2026
Logistic regression
Numerical Example 2: Study Hours Pass(1)/Fail(0)
2. How many hours of study a students 29 0
requires to pass a course with probability 15 0
of more than 95% ?
33 1
28 1
39 1
Logistic regression
Numerical Example 2: Study Hours Pass(1)/Fail(0)
2. How many hours of study a students 29 0
requires to pass a course with probability 15 0
of more than 95% ?
33 1
28 1
39 1
50
2/27/2026
Logistic regression
Numerical Example 2: Study Hours Pass(1)/Fail(0)
2. How many hours of study a students 29 0
requires to pass a course with probability 15 0
of more than 95% ?
33 1
28 1
39 1
Polynomial Regression
51
2/27/2026
Polynomial Regression
Polynomial Regression
52
2/27/2026
Polynomial Regression
n = No. of
elements
Polynomial Regression
Numerical Example:
Apply Polynomial Regression on
given a dataset and find the
equation.
Also predict the value of y when x =
7.
53
2/27/2026
Polynomial Regression
Numerical Example:
Polynomial Regression
Numerical Example:
Equation:
54
2/27/2026
Polynomial Regression
Advantages
Captures non-linear relationships.
More flexible than simple linear regression.
Disadvantages
Overfitting if polynomial degree is too high.
Sensitive to outliers.
Interpretation becomes harder for high-degree polynomials.
Polynomial Regression
55