Presentation by: Dr. N.
Yuvaraj , SCOPE,VIT
Problems on linear regression
PRESENTATION BY: YUVARAJ , SCOPE, VIT
Presentation by: Dr. [Link] , SCOPE,VIT
Linear regression
A teacher wants to predict the exam score of students based on the
number of hours they study using simple linear regression.
Fit a simple linear regression model using the
Hours Exam form: Y=β0+β1X where:
Student
Studied (X) Score (Y) 1. Y = predicted exam score
A 1 35 2. X = hours studied
3. β0, β1 are intercept and slope
B 2 40
1. Calculate the values of β0 and β1 using the least
C 3 50 squares method.
D 4 55 [Link] the model to predict the exam score for:
E 5 65 1. a student who studies 3.5 hours
2. a student who studies 7 hours
F 6 70
[Link]: The regression line & Actual data points
4. Interpret the meaning of β1 in this context.
2
PRESENTATION BY: YUVARAJ , SCOPE, VIT
Presentation by: Dr. [Link] , SCOPE,VIT
Linear regression
Solution: Calculate the values of β0 and β1 using the least squares method.
Hours Exam
Studied (X) Score (Y)
1 35
2 40
3 50
4 55
5 65
6 70
PRESENTATION BY: YUVARAJ , SCOPE, VIT
Presentation by: Dr. [Link] , SCOPE,VIT
Linear regression
Solution: Calculate the values of β0 and β1 using the least squares method
PRESENTATION BY: YUVARAJ , SCOPE, VIT
Presentation by: Dr. [Link] , SCOPE,VIT
Linear regression
Solution: Calculate the values of β0 and β1 using the least squares method
PRESENTATION BY: YUVARAJ , SCOPE, VIT
Presentation by: Dr. [Link] , SCOPE,VIT
Linear regression
2. Use the model to predict the exam score for:
1.a student who studies 3.5 hours
2.a student who studies 7 hours
1. For 3.5 Hours
2. For 7 Hours
3. Interpretation of β1=7.29
For every additional hour a student studies, their predicted exam
score increases by approximately 7.29 points.
6
PRESENTATION BY: YUVARAJ , SCOPE, VIT
Presentation by: Dr. [Link] , SCOPE,VIT
Linear regression
Blue points: Actual student scores
Red line: Predicted regression line
Green & Orange dots:
Predictions for 3.5 and 7 hours
respectively
PRESENTATION BY: YUVARAJ , SCOPE, VIT
Presentation by: Dr. [Link] , SCOPE,VIT
Logistic Regression
PRESENTATION BY: YUVARAJ , SCOPE, VIT
Presentation by: Dr. [Link] , SCOPE,VIT
Logistic Regression – Example 1
¡ Predict if a student passes (1) or fails (0) an exam based on hours studied
using logistic regression.
Hours Result Logistic Regression Model
Student
Studied (X) (Y)
A 1 0
B 2 0
C 3 0
D 4 1
We want to find the best values for β0 and
E 5 1
β1 that maximize the likelihood.
F 6 1
9
PRESENTATION BY: YUVARAJ , SCOPE, VIT
Presentation by: Dr. [Link] , SCOPE,VIT
Logistic Regression – Example 1
¡ Predict if a student passes (1) or fails (0) based on hours studied
Initial try with : β0=−6 ; β1=1.2
X Y z = -6 + p = 1 / (1 +
(Hours) (Actual) 1.2X e^(-z))
1 0 -4.8 0.0082
2 0 -3.6 0.0266
3 0 -2.4 0.0832
4 1 -1.2 0.2315
5 1 0.0 0.5000
6 1 1.2 0.7685
10
PRESENTATION BY: YUVARAJ , SCOPE, VIT
Presentation by: Dr. [Link] , SCOPE,VIT
Logistic Regression – Example 1
¡ Compute Log-Likelihood
X Y p Log-likelihood term
1 0 0.0082 log (1−0.0082)=log (0.9918)=−0.0082
2 0 0.0266 log (0.9734)= -0.0269 logL≈−0.0082−0.0269
−0.0866−1.464−0.693
3 0 0.0832 log (0.9168)= -0.0866 1−0.2633
4 1 0.2315 log (0.2315)= -1.464
LLH =−2.5421
5 1 0.5 log (0.5)=−0.6931
6 1 0.7685 log (0.7685)=−0.2633 11
PRESENTATION BY: YUVARAJ , SCOPE, VIT
Presentation by: Dr. [Link] , SCOPE,VIT
Logistic Regression – Problem 2
12
PRESENTATION BY: YUVARAJ , SCOPE, VIT
Presentation by: Dr. [Link] , SCOPE,VIT
Logistic Regression – Problem 2
Use Case: Predicting Online Purchase Based on Time Spent on Website
A company uses logistic regression to predict whether a visitor will make a purchase (1 =
Yes, 0 = No) based on the time (in minutes) they spend on the website.
Model Parameters: β0=−2.5 ; β1=0.3
Visit Time on Site Actual Calculate the probability of purchase for each visitor
or (X) Purchase using the logistic regression formula.
1 2 No (0)
2 4 No (0)
3 5 Yes (1) Classify each visitor as Yes (1) or No (0) based on
4 6 Yes (1) the threshold: If p≥0.5⇒Yes ; Else⇒No
5 8 Yes (1) Compare the predictions with the actual
6 10 No (0) purchases, and compute:
7 12 Yes (1) •Number of correct predictions 13
•Accuracy (%)
PRESENTATION BY: YUVARAJ , SCOPE, VIT
Presentation by: Dr. [Link] , SCOPE,VIT
Logistic Regression - Problem
Given: Model Parameters: β0=−2.5 ; β1=0.3
Need to calculate:
X (Time p=1/ Prediction
Visitor z = -2.5 + 0.3·X Actual Correct?
on Site) (1 + e^-z) (p≥0.5)
1 2 -1.9 0.130 0 (No) 0 Yes
2 4 -1.3 0.214 0 (No) 0 Yes
3 5 -1.0 0.269 0 (No) 1 No
4 6 -0.7 0.331 0 (No) 1 No
5 8 -0.1 0.475 0 (No) 1 No
6 10 0.5 0.622 1 (Yes) 0 No 14
7 12 1.1 0.750 1 (Yes) 1 Yes
PRESENTATION BY: YUVARAJ , SCOPE, VIT
Presentation by: Dr. [Link] , SCOPE,VIT
Logistic Regression - Problem
Correct Predictions: 3 out of 7 (Visitors 1, 2, 7)
Incorrect Predictions: 4 out of 7
Accuracy: 3/7×100≈42.86%
Inferences
•The model correctly identifies short time visitors as non-buyers.
•But it fails to predict correctly for medium-range buyers (5–8 mins).
•One long-time visitor (10 mins) is wrongly predicted as a buyer.
This suggests the model may need:
•More data
•More features (like age, pages viewed, device type)
•Or parameter tuning to improve prediction performance 15
PRESENTATION BY: YUVARAJ , SCOPE, VIT
Presentation by: Dr. [Link] , SCOPE,VIT
Logistic Regression - Problem
•Blue curve: The logistic function
showing the predicted probability of
purchase for any time value.
•Dashed gray line at p = 0.5:
Classification threshold above this is
predicted as "Yes", below is "No".
•Dots on the curve:
• Green: Correct prediction
• Red: Wrong prediction
• Circle (o): Actual purchase (1)
• Cross (x): No purchase (0)
16
PRESENTATION BY: YUVARAJ , SCOPE, VIT
Presentation by: Dr. [Link] , SCOPE,VIT
Thank You
17
PRESENTATION BY: YUVARAJ , SCOPE, VIT