SlideShare a Scribd company logo
Programming for Data
Analysis
Week 9
Dr. Ferdin Joe John Joseph
Faculty of Information Technology
Thai – Nichi Institute of Technology, Bangkok
Today’s lesson
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
2
• Linear Regression
Prerequisite
• Pandas
• Numpy
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
3
New Library needed
• Scikit Learn
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
4
Regression
• Regression analysis is one of the most important fields in statistics
and machine learning.
• There are many regression methods available.
• Linear regression is one of them.
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
5
Linear Regression
• Linear regression is probably one of the most important and widely
used regression techniques.
• It’s among the simplest regression methods.
• One of its main advantages is the ease of interpreting results.
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
6
Types of Linear Regression
• Simple Linear Regression
• Multiple Linear Regression
• Polynomial Regression
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
7
Simple Linear Regression
• Simple or single-variate linear regression is the simplest case of linear
regression with a single independent variable, 𝐱 = 𝑥.
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
8
Simple Linear Regression
• It starts with a given set of input-output (𝑥-𝑦) pairs (green circles).
• These pairs are your observations.
• For example, the leftmost observation (green circle) has the input 𝑥 =
5 and the actual output (response) 𝑦 = 5.
• The next one has 𝑥 = 15 and 𝑦 = 20, and so on.
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
9
Multiple Linear Regression
• Multiple or multivariate linear regression is a case of linear regression
with two or more independent variables.
• If there are just two independent variables, the estimated regression
function is 𝑓(𝑥₁, 𝑥₂) = 𝑏₀ + 𝑏₁𝑥₁ + 𝑏₂𝑥₂.
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
10
Polynomial Regression
• Polynomial regression is a generalized case of linear regression.
• The simplest example of polynomial regression has a single
independent variable, and the estimated regression function is a
polynomial of degree 2: 𝑓(𝑥) = 𝑏₀ + 𝑏₁𝑥 + 𝑏₂𝑥².
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
11
Underfitting and Overfitting
• Underfitting occurs when a model can’t accurately capture the
dependencies among data, usually as a consequence of its own
simplicity.
• Overfitting happens when a model learns both dependencies among
data and random fluctuations.
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
12
Underfitting
• The given plot shows a linear regression line that has a low 𝑅². It
might also be important that a straight line can’t take into account the
fact that the actual response increases as 𝑥 moves away from 25
towards zero. This is likely an example of underfitting.
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
13
Overfitting
• The given plot presents polynomial regression with the degree equal
to 3. The value of 𝑅² is higher than in the preceding cases. This model
behaves better with known data than the previous ones.
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
14
Well fitted
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
15
Linear Relationship
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
16
Positive Linear Relationship Negative Linear Relationship
Simple Linear Regression With scikit-learn
There are five basic steps when you’re implementing linear regression:
• 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.
• Visualize
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
17
Import the packages and classes you need
• The first step is to import the package numpy and the class
LinearRegression from sklearn.linear_model:
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
18
Provide data
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
19
Create a model and fit it
model = LinearRegression()
model = LinearRegression().fit(x, y)
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
20
Get results
• r_sq = model.score(x, y)
• print('coefficient of determination:', r_sq)
• print('intercept:', model.intercept_)
• print('slope:', model.coef_)
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
21
Predict Response
• 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')
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
22
Predict Response
• x_new = np.arange(5).reshape((-1, 1))
• print(x_new)
• y_new = model.predict(x_new)
• print(y_new)
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
23
Display in a plot
import matplotlib.pyplot as plt
plt.plot(x, y, label = "actual")
plt.plot(x_new, y_new, label = "Predicted")
plt.legend()
plt.show()
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
24
Multiple Linear Regression
• Import packages, classes and data
• Create Model and fit it
• Get results
• Predict Response
• Visualize
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
25
Get Data
x = [[0, 1], [5, 1], [15, 2], [25, 5], [35, 11], [45, 15], [55, 34], [60, 35]]
y = [4, 5, 20, 14, 32, 22, 38, 43]
x, y = np.array(x), np.array(y)
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
26
Create Model and fit
model = LinearRegression().fit(x, y)
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
27
Get Results
r_sq = model.score(x, y)
print('coefficient of determination:', r_sq)
print('intercept:', model.intercept_)
print('slope:', model.coef_)
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
28
Predict Response
y_pred = model.predict(x)
print('predicted response:', y_pred, sep='n’)
y_pred = model.intercept_ + np.sum(model.coef_ * x, axis=1)
print('predicted response:', y_pred, sep='n’)
y_pred=model.predict(x)
y_pred=model.intercept_+np.sum(model.coef_*x,axis=1)
x_new = [[0, 1], [5, 1], [15, 2], [25, 5], [35, 11], [45, 15], [55, 34], [60,
35]]
y_new = model.predict(x_new)
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
29
Polynomial Regression
• Import packages and classes
• Provide Data
• Create a model and fit it
• Get results
• Predict Response
• Visualize
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
30
Import packages and classes
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
31
Provide Data
x = np.array([5, 15, 25, 35, 45, 55]).reshape((-1, 1))
y = np.array([15, 11, 2, 8, 25, 32])
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
32
Transform input data
transformer = PolynomialFeatures(degree=2, include_bias=False)
transformer.fit(x)
x_ = transformer.transform(x)
x_ = PolynomialFeatures(degree=2, include_bias=False).fit_transform(x)
print(x_)
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
33
Create a model and fit it
model = LinearRegression().fit(x_, y)
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
34
Get Results
# Step 4: Get results
r_sq = model.score(x_, y)
intercept, coefficients = model.intercept_, model.coef_
# Step 5: Predict
y_pred = model.predict(x_)
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
35
Advanced Linear Regression using stats
models
• Import Packages
• Provide Data and Transform inputs
• Create Model and fit it
• Get Results
• Predict Response
• Visualize
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
36
Import packages
import statsmodels.api as sm
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
37
Provide data and transform inputs
x = [[0, 1], [5, 1], [15, 2], [25, 5], [35, 11], [45, 15], [55, 34], [60, 35]]
y = [4, 5, 20, 14, 32, 22, 38, 43]
x, y = np.array(x), np.array(y)
x = sm.add_constant(x)
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
38
Create Model and fit it
model = sm.OLS(y, x)
results = model.fit()
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
39
Get Results
print(results.summary())
print('coefficient of determination:', results.rsquared)
print('adjusted coefficient of determination:', results.rsquared_adj)
print('regression coefficients:', results.params)
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
40
Predict Response
print('predicted response:', results.fittedvalues, sep='n')
print('predicted response:', results.predict(x), sep='n’)
x_new = sm.add_constant(np.arange(10).reshape((-1, 2)))
print(x_new)
y_new = results.predict(x_new)
print(y_new)
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
41
DSA 207 – Linear Regression
• Linear Regression
Faculty of Information Technology, Thai - Nichi Institute of
Technology, Bangkok
42

More Related Content

What's hot

Week 1: Programming for Data Analysis
Week 1: Programming for Data AnalysisWeek 1: Programming for Data Analysis
Week 1: Programming for Data Analysis
Ferdin Joe John Joseph PhD
 
Blockchain Technology - Week 11 - Thai-Nichi Institute of Technology
Blockchain Technology - Week 11 - Thai-Nichi Institute of TechnologyBlockchain Technology - Week 11 - Thai-Nichi Institute of Technology
Blockchain Technology - Week 11 - Thai-Nichi Institute of Technology
Ferdin Joe John Joseph PhD
 
Data wrangling week 10
Data wrangling week 10Data wrangling week 10
Data wrangling week 10
Ferdin Joe John Joseph PhD
 
Blockchain Technology - Week 9 - Blockciphers
Blockchain Technology - Week 9 - BlockciphersBlockchain Technology - Week 9 - Blockciphers
Blockchain Technology - Week 9 - Blockciphers
Ferdin Joe John Joseph PhD
 
Blockchain Technology - Week 1 - Introduction to Blockchain
Blockchain Technology - Week 1 - Introduction to BlockchainBlockchain Technology - Week 1 - Introduction to Blockchain
Blockchain Technology - Week 1 - Introduction to Blockchain
Ferdin Joe John Joseph PhD
 
Data wrangling week3
Data wrangling week3Data wrangling week3
Data wrangling week3
Ferdin Joe John Joseph PhD
 
Blockchain Technology - Week 2 - Blockchain Terminologies
Blockchain Technology - Week 2 - Blockchain TerminologiesBlockchain Technology - Week 2 - Blockchain Terminologies
Blockchain Technology - Week 2 - Blockchain Terminologies
Ferdin Joe John Joseph PhD
 
Blockchain Technology - Week 4 - Hyperledger and Smart Contracts
Blockchain Technology - Week 4 - Hyperledger and Smart ContractsBlockchain Technology - Week 4 - Hyperledger and Smart Contracts
Blockchain Technology - Week 4 - Hyperledger and Smart Contracts
Ferdin Joe John Joseph PhD
 
Data wrangling week 6
Data wrangling week 6Data wrangling week 6
Data wrangling week 6
Ferdin Joe John Joseph PhD
 
Data wrangling week2
Data wrangling week2Data wrangling week2
Data wrangling week2
Ferdin Joe John Joseph PhD
 
Blockchain Technology - Week 10 - CAP Teorem, Byzantines General Problem
Blockchain Technology - Week 10 - CAP Teorem, Byzantines General ProblemBlockchain Technology - Week 10 - CAP Teorem, Byzantines General Problem
Blockchain Technology - Week 10 - CAP Teorem, Byzantines General Problem
Ferdin Joe John Joseph PhD
 
Data wrangling week1
Data wrangling week1Data wrangling week1
Data wrangling week1
Ferdin Joe John Joseph PhD
 
Blockchain Technology - Week 3 - FinTech and Cryptocurrencies
Blockchain Technology - Week 3 - FinTech and CryptocurrenciesBlockchain Technology - Week 3 - FinTech and Cryptocurrencies
Blockchain Technology - Week 3 - FinTech and Cryptocurrencies
Ferdin Joe John Joseph PhD
 
Week 12: Cloud AI- DSA 441 Cloud Computing
Week 12: Cloud AI- DSA 441 Cloud ComputingWeek 12: Cloud AI- DSA 441 Cloud Computing
Week 12: Cloud AI- DSA 441 Cloud Computing
Ferdin Joe John Joseph PhD
 
Week 9: Relational Database Service Alibaba Cloud- DSA 441 Cloud Computing
Week 9: Relational Database Service Alibaba Cloud- DSA 441 Cloud ComputingWeek 9: Relational Database Service Alibaba Cloud- DSA 441 Cloud Computing
Week 9: Relational Database Service Alibaba Cloud- DSA 441 Cloud Computing
Ferdin Joe John Joseph PhD
 
Week 7: Object Storage Service Alibaba Cloud- DSA 441 Cloud Computing
Week 7: Object Storage Service Alibaba Cloud- DSA 441 Cloud ComputingWeek 7: Object Storage Service Alibaba Cloud- DSA 441 Cloud Computing
Week 7: Object Storage Service Alibaba Cloud- DSA 441 Cloud Computing
Ferdin Joe John Joseph PhD
 
Best Python Libraries For Data Science & Machine Learning | Edureka
Best Python Libraries For Data Science & Machine Learning | EdurekaBest Python Libraries For Data Science & Machine Learning | Edureka
Best Python Libraries For Data Science & Machine Learning | Edureka
Edureka!
 
Python For Data Analysis | Python Pandas Tutorial | Learn Python | Python Tra...
Python For Data Analysis | Python Pandas Tutorial | Learn Python | Python Tra...Python For Data Analysis | Python Pandas Tutorial | Learn Python | Python Tra...
Python For Data Analysis | Python Pandas Tutorial | Learn Python | Python Tra...
Edureka!
 
Why Python?
Why Python?Why Python?
Why Python?
Adam Pah
 

What's hot (20)

Week 1: Programming for Data Analysis
Week 1: Programming for Data AnalysisWeek 1: Programming for Data Analysis
Week 1: Programming for Data Analysis
 
Blockchain Technology - Week 11 - Thai-Nichi Institute of Technology
Blockchain Technology - Week 11 - Thai-Nichi Institute of TechnologyBlockchain Technology - Week 11 - Thai-Nichi Institute of Technology
Blockchain Technology - Week 11 - Thai-Nichi Institute of Technology
 
Data wrangling week 10
Data wrangling week 10Data wrangling week 10
Data wrangling week 10
 
Data Wrangling Week 4
Data Wrangling Week 4Data Wrangling Week 4
Data Wrangling Week 4
 
Blockchain Technology - Week 9 - Blockciphers
Blockchain Technology - Week 9 - BlockciphersBlockchain Technology - Week 9 - Blockciphers
Blockchain Technology - Week 9 - Blockciphers
 
Blockchain Technology - Week 1 - Introduction to Blockchain
Blockchain Technology - Week 1 - Introduction to BlockchainBlockchain Technology - Week 1 - Introduction to Blockchain
Blockchain Technology - Week 1 - Introduction to Blockchain
 
Data wrangling week3
Data wrangling week3Data wrangling week3
Data wrangling week3
 
Blockchain Technology - Week 2 - Blockchain Terminologies
Blockchain Technology - Week 2 - Blockchain TerminologiesBlockchain Technology - Week 2 - Blockchain Terminologies
Blockchain Technology - Week 2 - Blockchain Terminologies
 
Blockchain Technology - Week 4 - Hyperledger and Smart Contracts
Blockchain Technology - Week 4 - Hyperledger and Smart ContractsBlockchain Technology - Week 4 - Hyperledger and Smart Contracts
Blockchain Technology - Week 4 - Hyperledger and Smart Contracts
 
Data wrangling week 6
Data wrangling week 6Data wrangling week 6
Data wrangling week 6
 
Data wrangling week2
Data wrangling week2Data wrangling week2
Data wrangling week2
 
Blockchain Technology - Week 10 - CAP Teorem, Byzantines General Problem
Blockchain Technology - Week 10 - CAP Teorem, Byzantines General ProblemBlockchain Technology - Week 10 - CAP Teorem, Byzantines General Problem
Blockchain Technology - Week 10 - CAP Teorem, Byzantines General Problem
 
Data wrangling week1
Data wrangling week1Data wrangling week1
Data wrangling week1
 
Blockchain Technology - Week 3 - FinTech and Cryptocurrencies
Blockchain Technology - Week 3 - FinTech and CryptocurrenciesBlockchain Technology - Week 3 - FinTech and Cryptocurrencies
Blockchain Technology - Week 3 - FinTech and Cryptocurrencies
 
Week 12: Cloud AI- DSA 441 Cloud Computing
Week 12: Cloud AI- DSA 441 Cloud ComputingWeek 12: Cloud AI- DSA 441 Cloud Computing
Week 12: Cloud AI- DSA 441 Cloud Computing
 
Week 9: Relational Database Service Alibaba Cloud- DSA 441 Cloud Computing
Week 9: Relational Database Service Alibaba Cloud- DSA 441 Cloud ComputingWeek 9: Relational Database Service Alibaba Cloud- DSA 441 Cloud Computing
Week 9: Relational Database Service Alibaba Cloud- DSA 441 Cloud Computing
 
Week 7: Object Storage Service Alibaba Cloud- DSA 441 Cloud Computing
Week 7: Object Storage Service Alibaba Cloud- DSA 441 Cloud ComputingWeek 7: Object Storage Service Alibaba Cloud- DSA 441 Cloud Computing
Week 7: Object Storage Service Alibaba Cloud- DSA 441 Cloud Computing
 
Best Python Libraries For Data Science & Machine Learning | Edureka
Best Python Libraries For Data Science & Machine Learning | EdurekaBest Python Libraries For Data Science & Machine Learning | Edureka
Best Python Libraries For Data Science & Machine Learning | Edureka
 
Python For Data Analysis | Python Pandas Tutorial | Learn Python | Python Tra...
Python For Data Analysis | Python Pandas Tutorial | Learn Python | Python Tra...Python For Data Analysis | Python Pandas Tutorial | Learn Python | Python Tra...
Python For Data Analysis | Python Pandas Tutorial | Learn Python | Python Tra...
 
Why Python?
Why Python?Why Python?
Why Python?
 

Similar to Week 9: Programming for Data Analysis

Data Wrangling Week 7
Data Wrangling Week 7Data Wrangling Week 7
Data Wrangling Week 7
Ferdin Joe John Joseph PhD
 
Deep Learning and CNN Architectures
Deep Learning and CNN ArchitecturesDeep Learning and CNN Architectures
Deep Learning and CNN Architectures
Ferdin Joe John Joseph PhD
 
2019 DSA 105 Introduction to Data Science Week 3
2019 DSA 105 Introduction to Data Science Week 32019 DSA 105 Introduction to Data Science Week 3
2019 DSA 105 Introduction to Data Science Week 3
Ferdin Joe John Joseph PhD
 
Lecture 1.pptx
Lecture 1.pptxLecture 1.pptx
Data Structures and Algorithm - Week 3 - Stacks and Queues
Data Structures and Algorithm - Week 3 - Stacks and QueuesData Structures and Algorithm - Week 3 - Stacks and Queues
Data Structures and Algorithm - Week 3 - Stacks and Queues
Ferdin Joe John Joseph PhD
 
Data Structures and Algorithm - Week 11 - Algorithm Analysis
Data Structures and Algorithm - Week 11 - Algorithm AnalysisData Structures and Algorithm - Week 11 - Algorithm Analysis
Data Structures and Algorithm - Week 11 - Algorithm Analysis
Ferdin Joe John Joseph PhD
 
IC2IT 2013 Presentation
IC2IT 2013 PresentationIC2IT 2013 Presentation
IC2IT 2013 Presentation
Chittagong Independent University
 
IC2IT 2013 Presentation
IC2IT 2013 PresentationIC2IT 2013 Presentation
IC2IT 2013 Presentation
Chittagong Independent University
 
Data wrangling week 9
Data wrangling week 9Data wrangling week 9
Data wrangling week 9
Ferdin Joe John Joseph PhD
 
2015 03-28-eb-final
2015 03-28-eb-final2015 03-28-eb-final
2015 03-28-eb-final
Christopher Wilson
 
Ade manual with co po-18scheme
Ade manual with co po-18schemeAde manual with co po-18scheme
Ade manual with co po-18scheme
AMC Engineering College
 
Accelerating the Pace of Engineering Education with Simulation, Hardware and ...
Accelerating the Pace of Engineering Education with Simulation, Hardware and ...Accelerating the Pace of Engineering Education with Simulation, Hardware and ...
Accelerating the Pace of Engineering Education with Simulation, Hardware and ...
Joachim Schlosser
 
INTERNSHIP presentation on machiine learning
INTERNSHIP presentation  on machiine learningINTERNSHIP presentation  on machiine learning
INTERNSHIP presentation on machiine learning
rushikeshgarkal23ve
 
Intelligent Career Guidance System.pptx
Intelligent Career Guidance System.pptxIntelligent Career Guidance System.pptx
Intelligent Career Guidance System.pptx
Anonymous366406
 
Analysis of Educational Robotics activities using a machine learning approach
Analysis of Educational Robotics activities using a machine learning approachAnalysis of Educational Robotics activities using a machine learning approach
Analysis of Educational Robotics activities using a machine learning approach
Lorenzo Cesaretti
 
Introduction to Data Science - Week 3 - Steps involved in Data Science
Introduction to Data Science - Week 3 - Steps involved in Data ScienceIntroduction to Data Science - Week 3 - Steps involved in Data Science
Introduction to Data Science - Week 3 - Steps involved in Data Science
Ferdin Joe John Joseph PhD
 
FDS_dept_ppt.pptx
FDS_dept_ppt.pptxFDS_dept_ppt.pptx
FDS_dept_ppt.pptx
SatyajitPatil42
 
Unsupervised learning networks
Unsupervised learning networksUnsupervised learning networks
Unsupervised learning networks
Dr. C.V. Suresh Babu
 
Relational algebra
Relational algebraRelational algebra
Relational algebra
Dr. C.V. Suresh Babu
 

Similar to Week 9: Programming for Data Analysis (20)

Data Wrangling Week 7
Data Wrangling Week 7Data Wrangling Week 7
Data Wrangling Week 7
 
Deep Learning and CNN Architectures
Deep Learning and CNN ArchitecturesDeep Learning and CNN Architectures
Deep Learning and CNN Architectures
 
2019 DSA 105 Introduction to Data Science Week 3
2019 DSA 105 Introduction to Data Science Week 32019 DSA 105 Introduction to Data Science Week 3
2019 DSA 105 Introduction to Data Science Week 3
 
Lecture 1.pptx
Lecture 1.pptxLecture 1.pptx
Lecture 1.pptx
 
Data Structures and Algorithm - Week 3 - Stacks and Queues
Data Structures and Algorithm - Week 3 - Stacks and QueuesData Structures and Algorithm - Week 3 - Stacks and Queues
Data Structures and Algorithm - Week 3 - Stacks and Queues
 
Data Structures and Algorithm - Week 11 - Algorithm Analysis
Data Structures and Algorithm - Week 11 - Algorithm AnalysisData Structures and Algorithm - Week 11 - Algorithm Analysis
Data Structures and Algorithm - Week 11 - Algorithm Analysis
 
IC2IT 2013 Presentation
IC2IT 2013 PresentationIC2IT 2013 Presentation
IC2IT 2013 Presentation
 
IC2IT 2013 Presentation
IC2IT 2013 PresentationIC2IT 2013 Presentation
IC2IT 2013 Presentation
 
Data wrangling week 9
Data wrangling week 9Data wrangling week 9
Data wrangling week 9
 
2015 03-28-eb-final
2015 03-28-eb-final2015 03-28-eb-final
2015 03-28-eb-final
 
Ade manual with co po-18scheme
Ade manual with co po-18schemeAde manual with co po-18scheme
Ade manual with co po-18scheme
 
Be computer-engineering-2012
Be computer-engineering-2012Be computer-engineering-2012
Be computer-engineering-2012
 
Accelerating the Pace of Engineering Education with Simulation, Hardware and ...
Accelerating the Pace of Engineering Education with Simulation, Hardware and ...Accelerating the Pace of Engineering Education with Simulation, Hardware and ...
Accelerating the Pace of Engineering Education with Simulation, Hardware and ...
 
INTERNSHIP presentation on machiine learning
INTERNSHIP presentation  on machiine learningINTERNSHIP presentation  on machiine learning
INTERNSHIP presentation on machiine learning
 
Intelligent Career Guidance System.pptx
Intelligent Career Guidance System.pptxIntelligent Career Guidance System.pptx
Intelligent Career Guidance System.pptx
 
Analysis of Educational Robotics activities using a machine learning approach
Analysis of Educational Robotics activities using a machine learning approachAnalysis of Educational Robotics activities using a machine learning approach
Analysis of Educational Robotics activities using a machine learning approach
 
Introduction to Data Science - Week 3 - Steps involved in Data Science
Introduction to Data Science - Week 3 - Steps involved in Data ScienceIntroduction to Data Science - Week 3 - Steps involved in Data Science
Introduction to Data Science - Week 3 - Steps involved in Data Science
 
FDS_dept_ppt.pptx
FDS_dept_ppt.pptxFDS_dept_ppt.pptx
FDS_dept_ppt.pptx
 
Unsupervised learning networks
Unsupervised learning networksUnsupervised learning networks
Unsupervised learning networks
 
Relational algebra
Relational algebraRelational algebra
Relational algebra
 

More from Ferdin Joe John Joseph PhD

Invited Talk DGTiCon 2022
Invited Talk DGTiCon 2022Invited Talk DGTiCon 2022
Invited Talk DGTiCon 2022
Ferdin Joe John Joseph PhD
 
Week 11: Cloud Native- DSA 441 Cloud Computing
Week 11: Cloud Native- DSA 441 Cloud ComputingWeek 11: Cloud Native- DSA 441 Cloud Computing
Week 11: Cloud Native- DSA 441 Cloud Computing
Ferdin Joe John Joseph PhD
 
Week 10: Cloud Security- DSA 441 Cloud Computing
Week 10: Cloud Security- DSA 441 Cloud ComputingWeek 10: Cloud Security- DSA 441 Cloud Computing
Week 10: Cloud Security- DSA 441 Cloud Computing
Ferdin Joe John Joseph PhD
 
Week 6: Server Load Balancer and Auto Scaling Alibaba Cloud- DSA 441 Cloud Co...
Week 6: Server Load Balancer and Auto Scaling Alibaba Cloud- DSA 441 Cloud Co...Week 6: Server Load Balancer and Auto Scaling Alibaba Cloud- DSA 441 Cloud Co...
Week 6: Server Load Balancer and Auto Scaling Alibaba Cloud- DSA 441 Cloud Co...
Ferdin Joe John Joseph PhD
 
Week 5: Elastic Compute Service (ECS) with Alibaba Cloud- DSA 441 Cloud Compu...
Week 5: Elastic Compute Service (ECS) with Alibaba Cloud- DSA 441 Cloud Compu...Week 5: Elastic Compute Service (ECS) with Alibaba Cloud- DSA 441 Cloud Compu...
Week 5: Elastic Compute Service (ECS) with Alibaba Cloud- DSA 441 Cloud Compu...
Ferdin Joe John Joseph PhD
 
Week 4: Big Data and Hadoop in Alibaba Cloud - DSA 441 Cloud Computing
Week 4: Big Data and Hadoop in Alibaba Cloud - DSA 441 Cloud ComputingWeek 4: Big Data and Hadoop in Alibaba Cloud - DSA 441 Cloud Computing
Week 4: Big Data and Hadoop in Alibaba Cloud - DSA 441 Cloud Computing
Ferdin Joe John Joseph PhD
 
Week 3: Virtual Private Cloud, On Premise, IaaS, PaaS, SaaS - DSA 441 Cloud C...
Week 3: Virtual Private Cloud, On Premise, IaaS, PaaS, SaaS - DSA 441 Cloud C...Week 3: Virtual Private Cloud, On Premise, IaaS, PaaS, SaaS - DSA 441 Cloud C...
Week 3: Virtual Private Cloud, On Premise, IaaS, PaaS, SaaS - DSA 441 Cloud C...
Ferdin Joe John Joseph PhD
 
Week 2: Virtualization and VM Ware - DSA 441 Cloud Computing
Week 2: Virtualization and VM Ware - DSA 441 Cloud ComputingWeek 2: Virtualization and VM Ware - DSA 441 Cloud Computing
Week 2: Virtualization and VM Ware - DSA 441 Cloud Computing
Ferdin Joe John Joseph PhD
 
Week 1: Introduction to Cloud Computing - DSA 441 Cloud Computing
Week 1: Introduction to Cloud Computing - DSA 441 Cloud ComputingWeek 1: Introduction to Cloud Computing - DSA 441 Cloud Computing
Week 1: Introduction to Cloud Computing - DSA 441 Cloud Computing
Ferdin Joe John Joseph PhD
 
Sept 6 2021 BTech Artificial Intelligence and Data Science curriculum
Sept 6 2021 BTech Artificial Intelligence and Data Science curriculumSept 6 2021 BTech Artificial Intelligence and Data Science curriculum
Sept 6 2021 BTech Artificial Intelligence and Data Science curriculum
Ferdin Joe John Joseph PhD
 
Hadoop in Alibaba Cloud
Hadoop in Alibaba CloudHadoop in Alibaba Cloud
Hadoop in Alibaba Cloud
Ferdin Joe John Joseph PhD
 
Cloud Computing Essentials in Alibaba Cloud
Cloud Computing Essentials in Alibaba CloudCloud Computing Essentials in Alibaba Cloud
Cloud Computing Essentials in Alibaba Cloud
Ferdin Joe John Joseph PhD
 
Transforming deep into transformers – a computer vision approach
Transforming deep into transformers – a computer vision approachTransforming deep into transformers – a computer vision approach
Transforming deep into transformers – a computer vision approach
Ferdin Joe John Joseph PhD
 
Deep learning - Introduction
Deep learning - IntroductionDeep learning - Introduction
Deep learning - Introduction
Ferdin Joe John Joseph PhD
 
Data wrangling week 11
Data wrangling week 11Data wrangling week 11
Data wrangling week 11
Ferdin Joe John Joseph PhD
 

More from Ferdin Joe John Joseph PhD (15)

Invited Talk DGTiCon 2022
Invited Talk DGTiCon 2022Invited Talk DGTiCon 2022
Invited Talk DGTiCon 2022
 
Week 11: Cloud Native- DSA 441 Cloud Computing
Week 11: Cloud Native- DSA 441 Cloud ComputingWeek 11: Cloud Native- DSA 441 Cloud Computing
Week 11: Cloud Native- DSA 441 Cloud Computing
 
Week 10: Cloud Security- DSA 441 Cloud Computing
Week 10: Cloud Security- DSA 441 Cloud ComputingWeek 10: Cloud Security- DSA 441 Cloud Computing
Week 10: Cloud Security- DSA 441 Cloud Computing
 
Week 6: Server Load Balancer and Auto Scaling Alibaba Cloud- DSA 441 Cloud Co...
Week 6: Server Load Balancer and Auto Scaling Alibaba Cloud- DSA 441 Cloud Co...Week 6: Server Load Balancer and Auto Scaling Alibaba Cloud- DSA 441 Cloud Co...
Week 6: Server Load Balancer and Auto Scaling Alibaba Cloud- DSA 441 Cloud Co...
 
Week 5: Elastic Compute Service (ECS) with Alibaba Cloud- DSA 441 Cloud Compu...
Week 5: Elastic Compute Service (ECS) with Alibaba Cloud- DSA 441 Cloud Compu...Week 5: Elastic Compute Service (ECS) with Alibaba Cloud- DSA 441 Cloud Compu...
Week 5: Elastic Compute Service (ECS) with Alibaba Cloud- DSA 441 Cloud Compu...
 
Week 4: Big Data and Hadoop in Alibaba Cloud - DSA 441 Cloud Computing
Week 4: Big Data and Hadoop in Alibaba Cloud - DSA 441 Cloud ComputingWeek 4: Big Data and Hadoop in Alibaba Cloud - DSA 441 Cloud Computing
Week 4: Big Data and Hadoop in Alibaba Cloud - DSA 441 Cloud Computing
 
Week 3: Virtual Private Cloud, On Premise, IaaS, PaaS, SaaS - DSA 441 Cloud C...
Week 3: Virtual Private Cloud, On Premise, IaaS, PaaS, SaaS - DSA 441 Cloud C...Week 3: Virtual Private Cloud, On Premise, IaaS, PaaS, SaaS - DSA 441 Cloud C...
Week 3: Virtual Private Cloud, On Premise, IaaS, PaaS, SaaS - DSA 441 Cloud C...
 
Week 2: Virtualization and VM Ware - DSA 441 Cloud Computing
Week 2: Virtualization and VM Ware - DSA 441 Cloud ComputingWeek 2: Virtualization and VM Ware - DSA 441 Cloud Computing
Week 2: Virtualization and VM Ware - DSA 441 Cloud Computing
 
Week 1: Introduction to Cloud Computing - DSA 441 Cloud Computing
Week 1: Introduction to Cloud Computing - DSA 441 Cloud ComputingWeek 1: Introduction to Cloud Computing - DSA 441 Cloud Computing
Week 1: Introduction to Cloud Computing - DSA 441 Cloud Computing
 
Sept 6 2021 BTech Artificial Intelligence and Data Science curriculum
Sept 6 2021 BTech Artificial Intelligence and Data Science curriculumSept 6 2021 BTech Artificial Intelligence and Data Science curriculum
Sept 6 2021 BTech Artificial Intelligence and Data Science curriculum
 
Hadoop in Alibaba Cloud
Hadoop in Alibaba CloudHadoop in Alibaba Cloud
Hadoop in Alibaba Cloud
 
Cloud Computing Essentials in Alibaba Cloud
Cloud Computing Essentials in Alibaba CloudCloud Computing Essentials in Alibaba Cloud
Cloud Computing Essentials in Alibaba Cloud
 
Transforming deep into transformers – a computer vision approach
Transforming deep into transformers – a computer vision approachTransforming deep into transformers – a computer vision approach
Transforming deep into transformers – a computer vision approach
 
Deep learning - Introduction
Deep learning - IntroductionDeep learning - Introduction
Deep learning - Introduction
 
Data wrangling week 11
Data wrangling week 11Data wrangling week 11
Data wrangling week 11
 

Recently uploaded

Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP
 
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdfSample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Linda486226
 
一比一原版(NYU毕业证)纽约大学毕业证成绩单
一比一原版(NYU毕业证)纽约大学毕业证成绩单一比一原版(NYU毕业证)纽约大学毕业证成绩单
一比一原版(NYU毕业证)纽约大学毕业证成绩单
ewymefz
 
一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单
enxupq
 
Adjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTESAdjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTES
Subhajit Sahu
 
The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...
jerlynmaetalle
 
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape ReportSOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar
 
standardisation of garbhpala offhgfffghh
standardisation of garbhpala offhgfffghhstandardisation of garbhpala offhgfffghh
standardisation of garbhpala offhgfffghh
ArpitMalhotra16
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
ukgaet
 
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
John Andrews
 
Investigate & Recover / StarCompliance.io / Crypto_Crimes
Investigate & Recover / StarCompliance.io / Crypto_CrimesInvestigate & Recover / StarCompliance.io / Crypto_Crimes
Investigate & Recover / StarCompliance.io / Crypto_Crimes
StarCompliance.io
 
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
axoqas
 
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
ewymefz
 
Opendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptxOpendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptx
Opendatabay
 
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
Tiktokethiodaily
 
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Subhajit Sahu
 
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...Innovative Methods in Media and Communication Research by Sebastian Kubitschk...
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...
correoyaya
 
Tabula.io Cheatsheet: automate your data workflows
Tabula.io Cheatsheet: automate your data workflowsTabula.io Cheatsheet: automate your data workflows
Tabula.io Cheatsheet: automate your data workflows
alex933524
 
Empowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptxEmpowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptx
benishzehra469
 
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
axoqas
 

Recently uploaded (20)

Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
 
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdfSample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
 
一比一原版(NYU毕业证)纽约大学毕业证成绩单
一比一原版(NYU毕业证)纽约大学毕业证成绩单一比一原版(NYU毕业证)纽约大学毕业证成绩单
一比一原版(NYU毕业证)纽约大学毕业证成绩单
 
一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单
 
Adjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTESAdjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTES
 
The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...
 
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape ReportSOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape Report
 
standardisation of garbhpala offhgfffghh
standardisation of garbhpala offhgfffghhstandardisation of garbhpala offhgfffghh
standardisation of garbhpala offhgfffghh
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
 
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
 
Investigate & Recover / StarCompliance.io / Crypto_Crimes
Investigate & Recover / StarCompliance.io / Crypto_CrimesInvestigate & Recover / StarCompliance.io / Crypto_Crimes
Investigate & Recover / StarCompliance.io / Crypto_Crimes
 
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
 
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
 
Opendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptxOpendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptx
 
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
 
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
 
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...Innovative Methods in Media and Communication Research by Sebastian Kubitschk...
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...
 
Tabula.io Cheatsheet: automate your data workflows
Tabula.io Cheatsheet: automate your data workflowsTabula.io Cheatsheet: automate your data workflows
Tabula.io Cheatsheet: automate your data workflows
 
Empowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptxEmpowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptx
 
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
 

Week 9: Programming for Data Analysis

  • 1. Programming for Data Analysis Week 9 Dr. Ferdin Joe John Joseph Faculty of Information Technology Thai – Nichi Institute of Technology, Bangkok
  • 2. Today’s lesson Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 2 • Linear Regression
  • 3. Prerequisite • Pandas • Numpy Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 3
  • 4. New Library needed • Scikit Learn Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 4
  • 5. Regression • Regression analysis is one of the most important fields in statistics and machine learning. • There are many regression methods available. • Linear regression is one of them. Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 5
  • 6. Linear Regression • Linear regression is probably one of the most important and widely used regression techniques. • It’s among the simplest regression methods. • One of its main advantages is the ease of interpreting results. Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 6
  • 7. Types of Linear Regression • Simple Linear Regression • Multiple Linear Regression • Polynomial Regression Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 7
  • 8. Simple Linear Regression • Simple or single-variate linear regression is the simplest case of linear regression with a single independent variable, 𝐱 = 𝑥. Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 8
  • 9. Simple Linear Regression • It starts with a given set of input-output (𝑥-𝑦) pairs (green circles). • These pairs are your observations. • For example, the leftmost observation (green circle) has the input 𝑥 = 5 and the actual output (response) 𝑦 = 5. • The next one has 𝑥 = 15 and 𝑦 = 20, and so on. Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 9
  • 10. Multiple Linear Regression • Multiple or multivariate linear regression is a case of linear regression with two or more independent variables. • If there are just two independent variables, the estimated regression function is 𝑓(𝑥₁, 𝑥₂) = 𝑏₀ + 𝑏₁𝑥₁ + 𝑏₂𝑥₂. Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 10
  • 11. Polynomial Regression • Polynomial regression is a generalized case of linear regression. • The simplest example of polynomial regression has a single independent variable, and the estimated regression function is a polynomial of degree 2: 𝑓(𝑥) = 𝑏₀ + 𝑏₁𝑥 + 𝑏₂𝑥². Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 11
  • 12. Underfitting and Overfitting • Underfitting occurs when a model can’t accurately capture the dependencies among data, usually as a consequence of its own simplicity. • Overfitting happens when a model learns both dependencies among data and random fluctuations. Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 12
  • 13. Underfitting • The given plot shows a linear regression line that has a low 𝑅². It might also be important that a straight line can’t take into account the fact that the actual response increases as 𝑥 moves away from 25 towards zero. This is likely an example of underfitting. Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 13
  • 14. Overfitting • The given plot presents polynomial regression with the degree equal to 3. The value of 𝑅² is higher than in the preceding cases. This model behaves better with known data than the previous ones. Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 14
  • 15. Well fitted Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 15
  • 16. Linear Relationship Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 16 Positive Linear Relationship Negative Linear Relationship
  • 17. Simple Linear Regression With scikit-learn There are five basic steps when you’re implementing linear regression: • 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. • Visualize Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 17
  • 18. Import the packages and classes you need • The first step is to import the package numpy and the class LinearRegression from sklearn.linear_model: Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 18
  • 19. Provide data Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 19
  • 20. Create a model and fit it model = LinearRegression() model = LinearRegression().fit(x, y) Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 20
  • 21. Get results • r_sq = model.score(x, y) • print('coefficient of determination:', r_sq) • print('intercept:', model.intercept_) • print('slope:', model.coef_) Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 21
  • 22. Predict Response • 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') Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 22
  • 23. Predict Response • x_new = np.arange(5).reshape((-1, 1)) • print(x_new) • y_new = model.predict(x_new) • print(y_new) Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 23
  • 24. Display in a plot import matplotlib.pyplot as plt plt.plot(x, y, label = "actual") plt.plot(x_new, y_new, label = "Predicted") plt.legend() plt.show() Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 24
  • 25. Multiple Linear Regression • Import packages, classes and data • Create Model and fit it • Get results • Predict Response • Visualize Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 25
  • 26. Get Data x = [[0, 1], [5, 1], [15, 2], [25, 5], [35, 11], [45, 15], [55, 34], [60, 35]] y = [4, 5, 20, 14, 32, 22, 38, 43] x, y = np.array(x), np.array(y) Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 26
  • 27. Create Model and fit model = LinearRegression().fit(x, y) Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 27
  • 28. Get Results r_sq = model.score(x, y) print('coefficient of determination:', r_sq) print('intercept:', model.intercept_) print('slope:', model.coef_) Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 28
  • 29. Predict Response y_pred = model.predict(x) print('predicted response:', y_pred, sep='n’) y_pred = model.intercept_ + np.sum(model.coef_ * x, axis=1) print('predicted response:', y_pred, sep='n’) y_pred=model.predict(x) y_pred=model.intercept_+np.sum(model.coef_*x,axis=1) x_new = [[0, 1], [5, 1], [15, 2], [25, 5], [35, 11], [45, 15], [55, 34], [60, 35]] y_new = model.predict(x_new) Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 29
  • 30. Polynomial Regression • Import packages and classes • Provide Data • Create a model and fit it • Get results • Predict Response • Visualize Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 30
  • 31. Import packages and classes from sklearn.linear_model import LinearRegression from sklearn.preprocessing import PolynomialFeatures Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 31
  • 32. Provide Data x = np.array([5, 15, 25, 35, 45, 55]).reshape((-1, 1)) y = np.array([15, 11, 2, 8, 25, 32]) Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 32
  • 33. Transform input data transformer = PolynomialFeatures(degree=2, include_bias=False) transformer.fit(x) x_ = transformer.transform(x) x_ = PolynomialFeatures(degree=2, include_bias=False).fit_transform(x) print(x_) Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 33
  • 34. Create a model and fit it model = LinearRegression().fit(x_, y) Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 34
  • 35. Get Results # Step 4: Get results r_sq = model.score(x_, y) intercept, coefficients = model.intercept_, model.coef_ # Step 5: Predict y_pred = model.predict(x_) Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 35
  • 36. Advanced Linear Regression using stats models • Import Packages • Provide Data and Transform inputs • Create Model and fit it • Get Results • Predict Response • Visualize Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 36
  • 37. Import packages import statsmodels.api as sm Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 37
  • 38. Provide data and transform inputs x = [[0, 1], [5, 1], [15, 2], [25, 5], [35, 11], [45, 15], [55, 34], [60, 35]] y = [4, 5, 20, 14, 32, 22, 38, 43] x, y = np.array(x), np.array(y) x = sm.add_constant(x) Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 38
  • 39. Create Model and fit it model = sm.OLS(y, x) results = model.fit() Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 39
  • 40. Get Results print(results.summary()) print('coefficient of determination:', results.rsquared) print('adjusted coefficient of determination:', results.rsquared_adj) print('regression coefficients:', results.params) Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 40
  • 41. Predict Response print('predicted response:', results.fittedvalues, sep='n') print('predicted response:', results.predict(x), sep='n’) x_new = sm.add_constant(np.arange(10).reshape((-1, 2))) print(x_new) y_new = results.predict(x_new) print(y_new) Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 41
  • 42. DSA 207 – Linear Regression • Linear Regression Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok 42