0% found this document useful (0 votes)
46 views

6) TCE MOOC-jLinear Regression

Linear regression is a machine learning algorithm that predicts continuous output values using a linear equation. It finds the relationship between independent variables (inputs) and dependent variables (outputs) to make predictions. Simple linear regression uses a single input to predict the output, while multiple linear regression uses multiple inputs. Linear regression is commonly used for forecasting and determining causal effects between variables.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

6) TCE MOOC-jLinear Regression

Linear regression is a machine learning algorithm that predicts continuous output values using a linear equation. It finds the relationship between independent variables (inputs) and dependent variables (outputs) to make predictions. Simple linear regression uses a single input to predict the output, while multiple linear regression uses multiple inputs. Linear regression is commonly used for forecasting and determining causal effects between variables.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

LINEAR REGRESSION

APPLIED DATA SCIENCE WITH PYTHON

TCE Online Course - APPLIED DATA SCIENCE WITH PYTHON 1


Linear Regression
Linear Regression is a supervised machine learning algorithm where the predicted output is continuous
and has a constant slope.
It’s used to predict values within a continuous range, (e.g. sales, price,salary) rather than trying to
classify them into categories (e.g. cat, dog,yes,no).
Regression is a method of modelling a target value based on independent predictors.
This method is mostly used for forecasting and finding out cause and effect relationship between
variables.

TCE Online Course - <<Course Name>> 2


Linear Regression
Linear regression is a linear model, e.g. a model that assumes a linear relationship between the input
variables (x) and the output variable (y). More specifically, that y can be calculated from a linear
combination of the input variables (x).
When there is a single input variable (x), the method is referred to as simple linear regression. When
there are multiple input variables, it is refered as multiple linear regression.

TCE Online Course - <<Course Name>> 3


Simple Regression

Simple linear regression is useful for finding relationship between


two continuous variables.
Simple linear regression uses traditional form,

y=mx+b

where m and b are the slope and intercept variables.


x represents our input data and y represents our prediction.

TCE Online Course - APPLIED DATA SCIENCE WITH PYTHON 4


Simple Regression

From the given a dataset to find how much a company spends on Radio advertising in each year and its
annual Sales in terms of units sold.

TCE Online Course - <<Course Name>> 5


Making predictions

Our prediction function outputs an estimate of sales given a company’s radio


.
advertising spend and our current values for Weight and Bias.
Y=mX+C

Sales=Weight⋅Radio+Bias
Weight
The coefficient for the Radio independent variable. In machine learning we call
coefficients weights.
Radio
The independent variable. In machine learning we call these variables features.
Bias
The intercept where our line intercepts the y-axis. In machine learning we can
call intercepts bias.
Based on this, we have to find the correct values for Weight and Bias.

TCE Online Course - <<Course Name>> 6


Multivariable regression
A more complex, multi-variable linear equation might look like this,
where w represents the coefficients, or weights, our model will try to
learn.
f(x,y,z)= w1x+w2y+w3z
The variables x,y,z represent the attributes, or distinct pieces of
information, we have about each observation.
For sales predictions, these attributes might include a company’s
advertising spend on radio, TV, and newspapers.

Sales=w1 Radio+w2 TV+w3 News

TCE Online Course - APPLIED DATA SCIENCE WITH PYTHON 7


Making Predictions with Linear Regression
Given the representation is a linear equation, we are predicting
weight (y) from height (x).
Our linear regression model representation for this problem
would be:
Y=c+m*X or weight =c +m * height

Where c is the bias coefficient and m is the coefficient for the


height column. We use a learning technique to find a good set of
coefficient values. Once found, we can plug in different height
values to predict the weight.
For example, lets use c = 0.1 and m= 0.5. Let’s plug them in and
calculate the weight (in kilograms) for a person with the height of
182 centimeters.
weight = 0.1 + 0.5 * 182
weight = 91.1

TCE Online Course - <<Course Name>> 8


Linear Regression

TCE Online Course - APPLIED DATA SCIENCE WITH PYTHON 9


Application of linear-regression

Evaluating trends and sales estimates


Use linear-regression analysis to predict a salesperson’s total yearly sales (the dependent variable)
from independent variables such as age, education and years of experience.
Analyze pricing elasticity
Changes in pricing often impact consumer behavior — and linear regression can help to analyze how.
For instance, if the price of a particular product keeps changing, we can use regression analysis to see
whether consumption drops as the price increases. This information would be very helpful for retail
business.
Assess risk in an insurance company
It can be used to analyze risk in insurance company . For example, an insurance company might have
limited resources with which to investigate homeowners’ insurance claims; with linear regression, the
company’s team can build a model for estimating claims costs.

TCE Online Course - <<Course Name>> 10


Example :Linear Regression

TCE Online Course - <<Course Name>> 11


Example :Linear Regression

TCE Online Course - <<Course Name>> 12


Example :Linear Regression

Y=mX+c

σ 𝑋−𝑋ത 𝑌−𝑌ത
m = σ(𝑋−𝑋)2
=4/10=0.4

3.6=0.4*3+c
3.6=1.2+c
C=2.4

TCE Online Course - <<Course Name>> 13


New Predicted (Y)

m=0.4, c=2.4
Y=0.4X+2.4
Lets predict the new Y values for the given X=( 1,2,3,4,5)

Y=0.4*1+2.4=2.8
Y=0.4*2+2.4=3.2
Y=0.4*3+2.4=3.6
Y=0.4*4+2.4=4
Y=0.4*5+2.4=4.4

TCE Online Course - <<Course Name>> 14


Y predicted

TCE Online Course - <<Course Name>> 15


R-squared :
R-squared is a goodness-of-fit measure for linear regression
models.
This statistic indicates the percentage of the variance in the
dependent variable that the independent variables explain
collectively.
R-squared measures the strength of the relationship between
your model and the dependent variable
R-squared can take any values between 0 to 1.
After fitting a linear regression model, you need to determine
how well the model fits the data

TCE Online Course - <<Course Name>> 16


R Squared Error Rate:

TCE Online Course - <<Course Name>> 17


TCE Online Course - <<Course Name>> 18
Thank You!
C.DEISY August 2021

TCE Online Course - APPLIED DATA SCIENCE WITH PYTHON 19

You might also like