0% found this document useful (0 votes)
20 views32 pages

Lecture 4 Linear Regression 1 07032024 082032pm

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views32 pages

Lecture 4 Linear Regression 1 07032024 082032pm

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 32

LINEAR REGRESSION

Lecture 4
AGENDA
 Introduction to regression and linear regression.

 Real life applications of regression.

 Prediction through regression

2
REGRESSION (SUPERVISED MACHINE
LEARNING)
REGRESSION
In analyzing business and economic data, we often want
to know the relationship between two variables. The
correlation coefficient will give you information about the
nature and extent of the relationship. However, sometimes
we want to know by how much one variable changes because
of changes in other variables.

For example, a manager might be interested to know how


much sales will increase by an increase in advertisement
expenditure. To get the answer to such a question, we use
regression analysis.

4
REGRESSION
 Regression analysis can also be used to predict the value
of one variable based on another variable.

 In the regression model, we have dependent and


independent variables.

 The dependent variable is called the predicted or


response variable. The value of the dependent variable
depends on the value of the independent variable, which
is also called the explanatory or predictor variable.

5
LINEAR REGRESSION
 Linear regression is a fundamental statistical method used to
model the relationship between a dependent variable and one or
more independent variables by fitting a linear equation to
observed data.
 It assumes that there is a linear relationship between the
independent variables and the dependent variable.

Equation: Y = mX+b
UNDERSTANDING OF LINEAR REGRESSION

SCENARIO 1
Predicting Pizza Prices
 Step #1 : Data Collection
 Step #2 : Data Cleaning
 Step #3 : Calculations
 Step #4 : Prediction
 Step #5 : Visualization
UNDERSTANDING OF LINEAR REGRESSION

SCENARIO 2
Predicting Home Prices
 Step #1 : Data Collection
 Step #2 : Data Cleaning
 Step #3 : Calculations
 Step #4 : Prediction
 Step #5 : Visualization
UNDERSTANDING LINEAR REGRESSION

Red points shows the


available data points Once we have best fit There is a possibility
and blue line shows line we can tell price of to draw a multiple
the best fit any home as above lines with given data
points
UNDERSTANDING LINEAR REGRESSION
This blue line gives minimum error. We calculate the difference from given point to this line.
(we always takes square of each difference in order to avoid negative values {-1+1 will become 0}
LINEAR REGRESSION IN PYTHON
DATA FILE
IMPORTING LIBRARIES AND READ CSV FILE
DRAW PLOT USING MATPLOTLIB
DRAW PLOT USING MATPLOTLIB
REGRESSION ON GIVEN DATA

• First create an object of linear regression


• Fitting data means you are training your data with this model.
• First argument should be a 2D array( supply data frame here)
• Second argument should be y axis which is prices in this case
• This above model is ready to predict the prices
PREDICT PRICE WITH LINEAR REGRESSION
MODEL
WHY IT CAME UP WITH THIS PRICE?
VALUES OF COEFFICIENT AND INTERCEPT
SOLVE y = m*x + b
HOME TASK
CSV FILE CONTAINING THE AREAS, PREDICT PRICES
PREDICT PRICES USING ALREADY TRAINED
MODEL
PREDICT PRICES USING ALREADY TRAINED
MODEL
STORE PREDICTED PRICES IN CSV FILE
EXCLUDE INDEX VALUES WHILE WRITING
IN CSV FILE
HOW DOES LINEAR EQUATION WILL LOOK (FOR
ORIGINAL EXAMPLE)
SOME REAL LIFE APPLICATION FOR LINEAR
REGRESSION
 Financial analysts
 Financial analysts often use linear regression to forecast
investment returns and understand the operational and
financial performance of their organizations.
 Environmentalists
 Environmental jobs in areas like sustainability might also use
linear regression to compare the relationships of distinct
elements in nature. For example, the impact pollution levels
may have on temperature or simpler things like how the
amount of water plants receive affects their growth.
SOME REAL LIFE APPLICATION FOR LINEAR
REGRESSION
 Sports analysts
Sports analysts may use linear regression to help them provide
insightful information to sports team followers. For example,
they might reference the process to determine how well a
team may perform in its next game or how professional teams
within the same sports rank against each other.
 Medical researchers

Medical researchers often use linear regression to understand


the relationship between drug dosage and blood pressure of
patients.
SUMMARY
 In the most simple words, Linear Regression is
the supervised Machine Learning model in which the model
finds the best fit linear line between the independent and
dependent variable i.e it finds the linear relationship
between the dependent and independent variable.

You might also like