Professional Documents
Culture Documents
Linear Regression
Machine Learning in Hindi
Learning Objectives
In this module, we will learn to
• solve a regression problem
o Using the statistical approach
o Using the data Driven approach
Linear Regression
(using the statistical approach)
Machine Learning in Hindi
𝐲 = 𝐗𝛉 + 𝛆
Machine Learning in Hindi
𝐸 𝑦𝑖 = 𝐸 𝐱 𝑖T 𝛉 + εi = 𝐸 𝐱 𝑖T 𝛉 + 𝐸 𝜀𝑖
𝑚𝑦 = 𝐱 𝑖T 𝛉 + 0
𝑖
2
𝐸 𝑦𝑖 − 𝑚𝑦 = 𝜎𝑦𝟐𝑖
𝑖
2
=𝐸 𝑦𝑖 − 𝐱 𝑖T 𝛉
2
𝐸 𝜀𝑖 = 𝜎2
Machine Learning in Hindi
𝑛 2
1 𝑦 −𝐱 𝐓 𝛉
− 𝑖 𝒊2 [Using the assumptions of linear
𝐿′ 𝛉 = 𝑝 𝐲ȁ𝐗, 𝛉 = ෑ ⅇ 2𝜎
𝑖=1
2𝜋𝜎 2 regression]
𝑛
𝑛 2
1 1 𝑦𝑖 − 𝐱 𝑖T 𝛉
𝑝 𝐲ȁ𝐱, 𝛉 = 𝑛 ⅇ𝑥𝑝 − 2
2𝜋 𝜎
2 𝑛 2𝜎 2𝜎 2
𝑖=1
Machine Learning in Hindi
𝑛 Squared
2 Error
𝜃𝑚𝑙𝑒 = min 𝑦𝑖 − 𝐱 𝑖T 𝛉
𝛉
𝑖=1
Min
squared error
Machine Learning in Hindi
𝑦𝑖 = 𝜃0 + 𝜃1 𝑥𝑖1 + 𝜃2 𝑥𝑖2 + 𝜀𝑖
𝜃0
𝛉 = 𝜃1
𝜃2
Machine Learning in Hindi
2 2 2
𝐿 𝛉 = 𝑦1 − 𝜃0 − 𝑥11 𝜃1 − 𝑥12 𝜃2 + 𝑦2 − 𝜃0 − 𝑥21 𝜃1 − 𝑥22 𝜃2 + ….. + 𝑦n − 𝜃0 − 𝑥𝑛1 𝜃1 − 𝑥𝑛2 𝜃2
𝜕𝐿 𝛉
= 2 𝑦1 − 𝜃0 − 𝑥11 𝜃1 − 𝑥12 𝜃2 −1 + 2 𝑦2 − 𝜃0 − 𝑥21 𝜃1 − 𝑥22 𝜃2 −1 + ….. +
𝜕𝜃0
2 𝑦n − 𝜃0 − 𝑥𝑛1 𝜃1 − 𝑥𝑛2 𝜃2 −1
𝜕𝐿 𝛉 𝑛
= 2𝑖=1 𝑦𝑖 − 𝐱 𝑖T 𝛉 −1
𝜕𝜃0
Machine Learning in Hindi
𝜕𝐿 𝛉 𝑛
= 2𝑖=1 𝑦𝑖 − 𝐱 𝑖T 𝛉 −𝑥i1
𝜕𝜃1
𝜕𝐿 𝛉 𝑛
= 2𝑖=1 𝑦𝑖 − 𝐱 𝑖T 𝛉 −𝑥i2
𝜕𝜃2
𝜕𝐿 𝜃
𝜕𝜃0
𝜕𝐿 𝜃 𝑛 −1
𝛻𝐿 𝛉 = 𝜕𝜃1 = 2𝑖=1 𝑦𝑖 − 𝐱 𝑖T 𝛉 −𝑥i1 = 0
𝜕𝐿 𝜃 −𝑥i2
𝜕𝜃2
𝑛
− 2𝑖=1 𝑦𝑖 − 𝐱𝑖T 𝛉 𝐱 𝑖 = 0
Machine Learning in Hindi
𝑛 𝑛
𝑦𝑖 𝐱𝑖 = 𝐱𝑖 𝐱𝑖T 𝛉
𝑖=1 𝑖=1
𝑦1 𝐱1 + 𝑦2 𝐱 2 + ⋯ + 𝑦𝑛 𝐱 n = 𝐱1 𝐱1T 𝛉 + 𝐱 2 𝐱 2T 𝛉 + ⋯ + 𝐱 𝑛 𝐱 𝑛T 𝛉
𝐗𝐓 𝐲 = 𝐗𝐓 𝐗 𝛉
−1 𝐓
𝛉 = 𝐗𝐓𝐗 𝐗 𝐲
Machine Learning in Hindi
−1 T
𝐗† = 𝐗T 𝐗 𝐗 𝛉 = 𝐗†𝐲
−1 T
𝐗 † = 𝐗 −1 𝐗 T 𝐗 𝛉 = 𝐗†𝐲
= 𝐗 −1 𝐗 −1 𝐗 T 𝛉 = 𝐗 −1 𝐲
= 𝐗 −1 𝐲 = 𝐗𝛉
Machine Learning in Hindi
Drawbacks of MLE
1. Sensitivity to outliers: MLE assumes a specific probability distribution for the data which
can produce biased estimates if the data contains outliers.
2. Lack of robustness: Small changes in the data can lead to large changes in the estimates of
the parameters. This can be a problem if the data is noisy or contains errors.
3. Overfitting: MLE can suffer from overfitting if the model is too complex or if the data is
limited. Overfitting occurs when the model fits the noise in the data rather than the
underlying pattern, which can lead to poor generalization performance on new data.
4. Computational complexity: MLE can be computationally complex, especially for high-
dimensional data or complex models. This can make it difficult to estimate the parameters or
to perform inference on the model.
Linear Regression
(Data Driven Approach)
Machine Learning in Hindi
𝛉 = 𝐗†𝐲
where
−1 T
𝐗† = 𝐗T 𝐗 𝐗
Linear Regression
(Types of Errors and Performance Metrics)
Machine Learning in Hindi
• Performance Metrics:
o R-squared score
Regression
line
Sum of Squares
due to Residual
Sum of Squares
(SSR)
Total (SST)
Sum of Squares
Error (SSE)
Mean of Response
Variable = mean of
yis
Y
X
Machine Learning in Hindi
Regression Errors
➢ Sum of Squares Total (SST) / Total Squared Error (TSS)
𝑛
2
SST = 𝑦𝑖 − 𝑚
𝑖=1
➢ Sum of Squares due to Regression (SSR)/ Residual Sum of Squares (RSS)
𝑛
2
SSR = 𝑦𝑖 − 𝑦ෝ𝑖
𝑖=1
➢ Sum of Squares error (SSE) / Explained Sum of Squares (ESS)
𝑛
2
SSE = 𝑚 − 𝑦ෝ𝑖
𝑖=1
Sum of Squares
Total (SST) Regression
line
Sum of Squares
due to Residual
(SSR)
Sum of Squares
Error (SSE)
Mean of Response
Variable = sample mean
of yis
Y
X
Machine Learning in Hindi
• The measure of the proportion of the variance in the dependent variable that can be
explained by the independent variables in the model.
o 𝑅2 = 1 ⟹ the model explains all the variance in the dependent variable
o 𝑅2 = 0 ⟹ the model does not explain any of the variance in the dependent variable
• Disadvantages:
o Gives equal weight to all errors, regardless of their values
Machine Learning in Hindi
• Disadvantages:
o Sensitive to outliers (a few large errors can have a
disproportionate impact on the metric)
Machine Learning in Hindi
• Disadvantages:
o Similar to MSE
Machine Learning in Hindi
Let us Try!
Explanatory variable Response variable
• Regression errors: (feature) (output)
• Sum of Squares Total (SST):
1 2
• Sum of Squares due to Regression (SSR):
• Sum of Squares error (SSE): 2 3
3 5
Performance Metric
• R-squared score: 4 6
• Mean Absolute error: 5 8
• Mean Squared error:
• Root Mean Squared error:
Machine Learning in Hindi
Let us Try!
Explanatory variable Response variable
• Regression errors: (feature) (output)
• Sum of Squares Total (SST): 22.8
1 2
• Sum of Squares due to Regression (SSR): 0.3
• Sum of Squares error (SSE): 22.5 2 3
3 5
Performance Metric
• R-squared score: 0.9869 4 6
• Mean Absolute error: 0.240 5 8
• Mean Squared error: 0.060
• Root Mean Squared error: 0.245
Machine Learning in Hindi
Try it Yourself!
Question: Let there be a dataset of 50 observations, where each data point consists of a single independent
variable (𝑥) and a single dependent variable (𝑦). You want to fit a linear regression model to this data to
predict 𝑦 based on 𝑥. After performing the regression analysis, you obtain the following regression
equation: 𝑦ො = 2.5 + 1.8𝑥
Using the above information, what would be the predicted value of 𝑦 for a value of 𝑥 equal to 3.2?
To Summarize
In this module, we discussed on
● What is linear regression?
● What are the different types of errors?
● How to solve the problem?
● We also looked at one example.