SlideShare a Scribd company logo
1 of 102
RV College
of
Engineering
Go, change the
world
Introduction to Machine
learning
What is a Math/Stats Model?
1. Often Describe Relationship between Variables
1. Types
- Deterministic Models (no randomness)
- Probabilistic Models (with randomness)
RV College
of
Engineering
Go, change the world
Deterministic Models
1. Hypothesize Exact Relationships
2. Suitable When Prediction Error is Negligible
3. Example: Body mass index (BMI) is measure of
body fat based
– Metric Formula: BMI = Weight in Kilograms
(Height in Meters)2
– Non-metric Formula: BMI = Weight (pounds)x703
(Height in inches)2
RV College
of
Engineering
Go, change the world
Probabilistic Models
1. Hypothesize 2 Components
• Deterministic
• Random Error
2. Example: Systolic blood pressure of newborns Is 6
Times the Age in days + Random Error
• SBP = 6xage(d) + ε
• Random Error May Be Due to Factors Other
Than age in days (e.g. Birthweight)
RV College
of
Engineering
Go, change the world
Types of
Probabilistic Models
Regression Models
• Relationship between one dependent variable
and explanatory variable(s)
• Use equation to set up relationship
• Numerical Dependent (Response) Variable
• 1 or More Numerical or Categorical Independent
(Explanatory) Variables
• Used Mainly for Prediction & Estimation
RV College
of
Engineering
Go, change the world
Regression Modeling Steps
• 1. Hypothesize Deterministic Component
• Estimate Unknown Parameters
• 2. Specify Probability Distribution of
Random Error Term
• Estimate Standard Deviation of Error
• 3. Evaluate the fitted Model
• 4. Use Model for Prediction & Estimation
RV College
of
Engineering
Go, change the world
Types of
Regression Models
RV College
of
Engineering
Go, change the world
Types of
Regression Models
Regression
Models
Types of
Regression Models
Regression
Models
Simple
1 Explanatory
Variabl
e
Types of
Regression Models
Regression
Models
2+ Explanatory
Variable
s
Simple Multiple
1 Explanatory
Variabl
e
Types of
Regression Models
Regression
Models
Linear
2+ Explanatory
Variable
s
Simple Multiple
1 Explanatory
Variabl
e
Types of
Regression Models
Regression
Models
Linear
Non-
Linear
2+ Explanatory
Variable
s
Simple Multiple
1 Explanatory
Variabl
e
Types of
Regression Models
Regression
Models
Linear
Non-
Linear
2+ Explanatory
Variable
s
Simple Multiple
Linear
1 Explanatory
Variabl
e
Types of
Regression Models
Regression
Models
Linear
Non-
Linear
2+ Explanatory
Variable
s
Simple Multiple
Linear
1 Explanatory
Variabl
e
Non-
Linear
Linear Regression Model
RV College
of
Engineering
Go, change the world
Types of
Regression Models
RV College
of
Engineering
Go, change the world
© 1984-1994 T/Maker Co.
RV College
of
Engineering
Go, change the world
Y X
i i i
= + +
β β ε
0 1
Linear Regression Model
• 1. Relationship Between Variables Is a
Linear Function
Dependent
(Response)
Variable
Independent (Explanatory)
Variable
Population
Slope
Population
Y-Intercept
Random
Error
RV College
of
Engineering
Go, change the world
Estimating Parameters:
Least Squares Method
RV College
of
Engineering
Go, change the world
Scatter plot
• 1. Plot of All (Xi, Yi) Pairs
• 2. Suggests How Well Model Will Fit
0
20
40
60
0 20 40 60
X
Y
RV College
of
Engineering
Go, change the world
How would you draw a line through the points?
How do you determine which line ‘fits best’?
0
20
40
60
0 20 40 60
X
Y
RV College
of
Engineering
Go, change the world
How would you draw a line through the points?
How do you determine which line ‘fits best’?
0
20
40
60
0 20 40 60
X
Y
Slope changed
Intercept unchanged
RV College
of
Engineering
Go, change the world
How would you draw a line through the points?
How do you determine which line ‘fits best’?
0
20
40
60
0 20 40 60
X
Y
Slope unchanged
Intercept changed
RV College
of
Engineering
Go, change the world
How would you draw a line through the points?
How do you determine which line ‘fits best’?
0
20
40
60
0 20 40 60
X
Y
Slope changed
Intercept changed
RV College
of
Engineering
Go, change the world
Least Squares
• 1. ‘Best Fit’ Means Difference Between
Actual Y Values & Predicted Y Values Are a
Minimum. But Positive Differences Off-Set
Negative ones
RV College
of
Engineering
Go, change the world
Least Squares
• 1. ‘Best Fit’ Means Difference Between
Actual Y Values & Predicted Y Values is a
Minimum. But Positive Differences Off-Set
Negative ones. So square errors!
RV College
of
Engineering
Go, change the world
Least Squares
• 1. ‘Best Fit’ Means Difference Between
Actual Y Values & Predicted Y Values Are a
Minimum. But Positive Differences Off-Set
Negative. So square errors!
• 2. LS Minimizes the Sum of the Squared
Differences (errors) (SSE)
RV College
of
Engineering
Go, change the world
Least Squares Graphically
RV College
of
Engineering
Go, change the world
Coefficient Equations
• Prediction equation
• Sample slope
• Sample Y - intercept
RV College
of
Engineering
Go, change the world
https://youtu.be/Ijd1PLmThsU
Derivation of Parameters (1)
• Least Squares (L-S): Minimize squared error
RV College
of
Engineering
Go, change the world
Derivation of Parameters (1)
• Least Squares (L-S): Minimize squared error
RV College
of
Engineering
Go, change the world
Computation Table
RV College
of
Engineering
Go, change the world
Interpretation of Coefficients
• 1. Slope (β1)
– Estimated Y Changes by β1 for Each 1 Unit
Increase in X
• If β1 = 2, then Y Is Expected to Increase by 2 for Each 1
Unit Increase in X
^
^
^
RV College
of
Engineering
Go, change the world
Interpretation of Coefficients
• 1. Slope (β1)
– Estimated Y Changes by β1 for Each 1 Unit
Increase in X
• If β1 = 2, then Y Is Expected to Increase by 2 for Each 1
Unit Increase in X
• 2. Y-Intercept (β0)
– Average Value of Y When X = 0
• If β0 = 4, then Average Y Is Expected to Be 4
When X Is 0
^
^
^
^
^
RV College
of
Engineering
Go, change the world
Parameter Estimation Example-1
• Obstetrics: What is the relationship between
Mother’s Estriol (harmone)level & Birthweight using the
following data?
Estriol Birthweight
(mg/24h) (g/1000)
1 1
2 1
3 2
4 2
5 4
RV College
of
Engineering
Go, change the world
Scatterplot
Birthweight vs. Estriol level
Birthweight
Estriol level
RV College
of
Engineering
Go, change the world
Parameter Estimation Solution Table
RV College
of
Engineering
Go, change the world
https://youtu.be/Ijd1PLmThsU
Parameter Estimation Solution
RV College
of
Engineering
Go, change the world
https://youtu.be/DSQ2plMtbLc
Coefficient Interpretation Solution
RV College
of
Engineering
Go, change the world
Coefficient Interpretation Solution
• 1. Slope (β1)
– Birthweight (Y) Is Expected to Increase by .7 Units
for Each 1 unit Increase in Estriol (X)
^
RV College
of
Engineering
Go, change the world
Coefficient Interpretation Solution
• 1. Slope (β1)
– Birthweight (Y) Is Expected to Increase by .7 Units
for Each 1 unit Increase in Estriol (X)
• 2. Intercept (β0)
– Average Birthweight (Y) Is -.10 Units When Estriol
level (X) Is 0
• Difficult to explain
• The birthweight should always be positive
^
^
RV College
of
Engineering
Go, change the world
Parameter Estimation Example-2
• A Veterinary doctor epidemiologist for the
county cooperative. You gather the following
data:
• Food (lb.) Milk yield (lb.)
4 3.0
6 5.5
10 6.5
12 9.0
• What is the relationship
between cows’ food intake and milk yield?
© 1984-1994 T/Maker Co.
RV College
of
Engineering
Go, change the world
Scatter plot
Milk Yield vs. Food intake*
M. Yield (lb.)
Food intake (lb.)
RV College
of
Engineering
Go, change the world
Parameter Estimation Solution Table
RV College
of
Engineering
Go, change the world
Parameter Estimation
RV College
of
Engineering
Go, change the world
Coefficient Interpretation
RV College
of
Engineering
Go, change the world
Coefficient Interpretation
• 1. Slope (β1)
– Milk Yield (Y) Is Expected to Increase by .65 lb.
for Each 1 lb. Increase in Food intake (X)
^
RV College
of
Engineering
Go, change the world
Coefficient Interpretation
• 1. Slope (β1)
– Milk Yield (Y) Is Expected to Increase by .65 lb.
for Each 1 lb. Increase in Food intake (X)
• 2. Y-Intercept (β0)
– Average Milk yield (Y) Is Expected to Be 0.8 lb.
When Food intake (X) Is 0
^
^
RV College
of
Engineering
Go, change the world
Implementation
• Import the packages and classes you need.
• Provide data to work with and eventually do appropriate
transformations.
• Create a regression model and fit it with existing data.
• Check the results of model fitting to know whether the model is
satisfactory.
• Apply the model for predictions.
RV College
of
Engineering
Go, change the world
RV College
of
Engineering
Go, change the world
Speeds of car : x -- age, y -- speed
x = [5,7,8,7,2,17,2,9,4,11,12,9,6]
y = [99,86,87,88,111,86,103,87,94,78,77,85,86]
import matplotlib.pyplot as plt
from scipy import stats
x = [5,7,8,7,2,17,2,9,4,11,12,9,6]
y = [99,86,87,88,111,86,103,87,94,78,77,85,86]
slope, intercept, r, p, std_err = stats.linregress(x, y)
def myfunc(x):
return slope * x + intercept
mymodel = list(map(myfunc, x))
plt.scatter(x, y)
plt.plot(x, mymodel)
plt.show()
RV College
of
Engineering
Go, change the world
from scipy import stats
x = [5,7,8,7,2,17,2,9,4,11,12,9,6]
y = [99,86,87,88,111,86,103,87,94,78,77,85,86]
slope, intercept, r, p, std_err = stats.linregress(x, y)
def myfunc(x):
return slope * x + intercept
speed = myfunc(10)
print(speed)
_____________________________________________________________________
x = [89,43,36,36,95,10,66,34,38,20,26,29,48,64,6,5,36,66,72,40]
y = [21,46,3,35,67,95,53,72,58,10,26,34,90,33,38,20,56,2,47,15]
import numpy as np
from sklearn.linear_model import LinearRegression
x = np.array([5, 15, 25, 35, 45, 55]).reshape((-1, 1))
y = np.array([5, 20, 14, 32, 22, 38])
print(x)
print(y)
model = LinearRegression().fit(x, y)
r_sq = model.score(x, y)
print('coefficient of determination:', r_sq)
print('intercept:', model.intercept_)
print('slope:', model.coef_)
“””new_model = LinearRegression().fit(x, y.reshape((-1, 1)))
print('intercept:', new_model.intercept_)
print('slope:', new_model.coef_)”””
y_pred = model.predict(x)
print('predicted response:', y_pred, sep='n')
y_pred = model.intercept_ + model.coef_ * x
print('predicted response:', y_pred, sep='n')
RV College
of
Engineering
Go, change the world
RV College
of
Engineering
Go, change the world
RV College
of
Engineering
Go, change the world
Linear regression Example-3
RV College
of
Engineering
Go, change the world
RV College
of
Engineering
Go, change the world
RV College
of
Engineering
Go, change the world
RV College
of
Engineering
Go, change the world
RV College
of
Engineering
Go, change the world
RV College
of
Engineering
Go, change the world
RV College
of
Engineering
Go, change the world
RV College
of
Engineering
Go, change the world
Example 4(statistical parameters)
• For two variables
• SST=120
• SSE=30.075
• SSR=SST-SSE=89.928
Statistical analysis
RV College
of
Engineering
Go, change the world
Coefficient of correlation ( r) = (R squared )^(½)=0.8656
90
Adjusted R2
• R2 Never Decreases When New X Variable Is Added
to Model (Disadvantage When Comparing Models)
• Solution: Adjusted R2
– Each additional variable reduces adjusted R2, unless SSE
goes up enough to compensate
Points Discussed :
1. coefficient of determination(R squared)
2. Adjusted R square
3. MSE mean square error
4. variance
5. correlation coefficient
6. intercept n slope
RV College
of
Engineering
Go, change the world
Simple non-linear Regression
https://youtu.be/JV-agdxZ74g
RV College
of
Engineering
Go, change the world
RV College
of
Engineering
Go, change the world
RV College
of
Engineering
Go, change the world
Continue----

More Related Content

Similar to Copy of simple Linear regression _1_RK (1).pptx

Using Qualitative Knowledge in Numerical Learning
Using Qualitative Knowledge in Numerical LearningUsing Qualitative Knowledge in Numerical Learning
Using Qualitative Knowledge in Numerical Learning
butest
 

Similar to Copy of simple Linear regression _1_RK (1).pptx (20)

AI3391 Artificial intelligence Session 28 Resolution.pptx
AI3391 Artificial intelligence Session 28 Resolution.pptxAI3391 Artificial intelligence Session 28 Resolution.pptx
AI3391 Artificial intelligence Session 28 Resolution.pptx
 
(7) Lesson 1.8 - Slope
(7) Lesson 1.8 - Slope(7) Lesson 1.8 - Slope
(7) Lesson 1.8 - Slope
 
Doe introductionh
Doe introductionhDoe introductionh
Doe introductionh
 
Regression
RegressionRegression
Regression
 
Improving predictions: Lasso, Ridge and Stein's paradox
Improving predictions: Lasso, Ridge and Stein's paradoxImproving predictions: Lasso, Ridge and Stein's paradox
Improving predictions: Lasso, Ridge and Stein's paradox
 
Logistic regression (blyth 2006) (simplified)
Logistic regression (blyth 2006) (simplified)Logistic regression (blyth 2006) (simplified)
Logistic regression (blyth 2006) (simplified)
 
Multiple linear regression II
Multiple linear regression IIMultiple linear regression II
Multiple linear regression II
 
Anov af03
Anov af03Anov af03
Anov af03
 
Using Qualitative Knowledge in Numerical Learning
Using Qualitative Knowledge in Numerical LearningUsing Qualitative Knowledge in Numerical Learning
Using Qualitative Knowledge in Numerical Learning
 
4.6 Exponential Growth and Decay
4.6 Exponential Growth and Decay4.6 Exponential Growth and Decay
4.6 Exponential Growth and Decay
 
Marcello Fiorentini
Marcello FiorentiniMarcello Fiorentini
Marcello Fiorentini
 
R meetup lm
R meetup lmR meetup lm
R meetup lm
 
Climate Extremes Workshop - Assessing models for estimation and methods for u...
Climate Extremes Workshop - Assessing models for estimation and methods for u...Climate Extremes Workshop - Assessing models for estimation and methods for u...
Climate Extremes Workshop - Assessing models for estimation and methods for u...
 
Design of Engineering Experiments Part 5
Design of Engineering Experiments Part 5Design of Engineering Experiments Part 5
Design of Engineering Experiments Part 5
 
Lecture slides stats1.13.l20.air
Lecture slides stats1.13.l20.airLecture slides stats1.13.l20.air
Lecture slides stats1.13.l20.air
 
Heteroscedasticity Remedial Measures.pptx
Heteroscedasticity Remedial Measures.pptxHeteroscedasticity Remedial Measures.pptx
Heteroscedasticity Remedial Measures.pptx
 
7 equilibrium 2021.docx
7 equilibrium 2021.docx7 equilibrium 2021.docx
7 equilibrium 2021.docx
 
DSD-INT 2017 A Metamodel To Estimate Run-Up Along Coral Reef-Lined Shorelines...
DSD-INT 2017 A Metamodel To Estimate Run-Up Along Coral Reef-Lined Shorelines...DSD-INT 2017 A Metamodel To Estimate Run-Up Along Coral Reef-Lined Shorelines...
DSD-INT 2017 A Metamodel To Estimate Run-Up Along Coral Reef-Lined Shorelines...
 
7. logistics regression using spss
7. logistics regression using spss7. logistics regression using spss
7. logistics regression using spss
 
Presentation on Regression Analysis
Presentation on Regression AnalysisPresentation on Regression Analysis
Presentation on Regression Analysis
 

Recently uploaded

Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Recently uploaded (20)

Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 

Copy of simple Linear regression _1_RK (1).pptx