Download as pdf or txt
Download as pdf or txt
You are on page 1of 42

Introduction to Machine

Learning
Week 9

Adeel Arif
Email: adeel.arif@ucp.edu.pk
Linear Regression Use

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Linear Regression Use

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Linear Regression Use

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Linear Regression Use

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Basic Question

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Independent and Dependent Variables

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Numerical and Categorical Values

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
ML Algorithms: Linear Regression

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
ML Algorithms: Linear Regression

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
ML Algorithms: Linear Regression

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Applications of Linear Regression

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Understanding Linear Regression

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Regression Equation

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Prediction using the Regression line

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Intuition behind the Regression line

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Intuition behind the Regression line

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Intuition behind the Regression line

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Intuition behind the Regression line

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Finding the Best fit line

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Finding the Best fit line

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Finding the Best fit line

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Finding the Best fit line

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Finding the Best fit line

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Sum of squared residuals

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Optimal rotation of line

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Multiple Linear Regression

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Use case implementation of Linear Regression

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Linear Regression
1
• Mean calculation: 𝑥ҧ = 𝛴𝑥𝑖
𝑛
1 2
• Variance of 𝑥: 𝑉𝑎𝑟 𝑥 = 𝛴 𝑥𝑖 − 𝑥ҧ
𝑛−1
Σ 𝑥𝑖 −𝑥ҧ 𝑦𝑖 −𝑦ത
• 𝑠𝑙𝑜𝑝𝑒 =
𝛴 𝑥𝑖 −𝑥ҧ 2
• Y intercept = 𝑦ത − 𝑠𝑙𝑜𝑝𝑒(𝑥)ҧ
• 𝑦ො = 𝑦𝑖𝑛𝑡𝑒𝑟𝑐𝑒𝑝𝑡 + 𝑠𝑙𝑜𝑝𝑒(𝑥)

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Example of linear regression

Independent variable (x) Dependent variable (y)


1 2
2 4
3 5
4 4
5 5

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
R-squared method
• 𝑅2 is quantifying the difference between the line and the mean.

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
R-squared method
• R-squared is a statistical method that determines the goodness of fit.
• It measures the strength of the relationship between the dependent
and independent variables on a scale of 0 − 100%.
• The high value of r-square determines the less difference between
the predicted values and actual values and hence represents a good
model.
• It is also called a coefficient of determination, or coefficient of
multiple determination for multiple regress.

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
R-Squared Method
𝑒𝑥𝑝𝑙𝑎𝑖𝑛𝑒𝑑 𝑣𝑎𝑟𝑖𝑎𝑡𝑖𝑜𝑛
• 𝑅2 =
𝑡𝑜𝑡𝑎𝑙 𝑣𝑎𝑟𝑖𝑎𝑡𝑖𝑜𝑛

𝑣𝑎𝑟𝑖𝑎𝑛𝑐𝑒 𝑚𝑒𝑎𝑛 −𝑣𝑎𝑟𝑖𝑎𝑛𝑐𝑒(𝑓𝑖𝑡)


• 𝑅2 =
𝑣𝑎𝑟𝑖𝑎𝑛𝑐𝑒(𝑚𝑒𝑎𝑛)

Σ 𝑦𝑖 −𝑦ො 𝑖 2
• 𝑅2 = 1 −
Σ 𝑦𝑖 −𝑦ത 𝑖 2

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
R square

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
R square

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
R square

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
R square

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
R squaree

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Linear Regression with 2 independent
variables

Y = a + b1 X1 + b2 X2
Example

X1 X2 Y
2 13 12
5 7 22
8 34 21
13 1 31
54 23 42
Reference
• https://www.youtube.com/watch?v=NUXdtN1W1FE&t=1040s

• https://www.youtube.com/watch?v=PaFPbb66DxQ

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23
Thanks
• Office:
Room 108, Block C.
Email: adeel.arif@ucp.edu.pk

• Course Website:
https://sites.google.com/view/adeel-arif/teaching/introduction-to-
machine-learning-s23

• Contact Card

https://sites.google.com/view/adeel-
arif/teaching/introduction-to-machine-learning-s23

You might also like