Linear Regression: Student: Mohammed Abu Musameh Supervisor: Eng. Akram Abu Garad
Linear Regression: Student: Mohammed Abu Musameh Supervisor: Eng. Akram Abu Garad
◦ Regression is the process of finding a model or function for distinguishing the data into continuous real values
instead of using classes or discrete values. It can also identify the distribution movement depending on the
historical data. Because a regression predictive model predicts a quantity, therefore, the skill of the model
must be reported as an error in those predictions.
◦ Classification is the process of finding or discovering a model or function which helps in separating the data
into multiple categorical classes i.e. discrete values. In classification, data is categorized under different labels
according to some parameters given in input and then the labels are predicted for the data.
Regression vs Classification (con’t)
PARAMENTER REGRESSION CLASSIFICATION
Mapping Function is used for mapping Mapping Function is used for mapping
Basic
of values to continuous output. of values to predefined classes.
Involves prediction of Continuous values Discrete values
Nature of the predicted data Ordered Unordered
by measurement of root mean square
Method of calculation by measuring accuracy
error
Once we find the best θ1 and θ2 values, we get the best fit line. So when we are finally using our
model for prediction, it will predict the value of y for the input value of x.
Linear Regression (con’t)
How to update θ1 and θ2 values to get the best fit line ?
Cost Function (J):
By achieving the best-fit regression line, the model aims to predict y value such that the error
difference between predicted value and true value is minimum. So, it is very important to
update the θ1 and θ2 values, to reach the best value that minimize the error between predicted y
value (pred) and true y value (y).
Cost function(J) of Linear Regression is the Root Mean Squared Error (RMSE) between predicted y value
(pred) and true y value (y).
Gradient Descent in Linear Regression
To update θ1 and θ2 values in order to reduce Cost function (minimizing RMSE value) and
achieving the best fit line the model uses Gradient Descent. The idea is to start with random
θ1 and θ2 values and then iteratively updating the values, reaching minimum cost.
In linear regression, the model targets to get the best-fit regression line to predict the
value of y based on the given input value (x). While training the model, the model
calculates the cost function which measures the Root Mean Squared error between the
predicted value (pred) and true value (y). The model targets to minimize the cost function.
Gradient Descent in Linear Regression
(con’t)
To minimize the cost function, the model needs to have the best value of θ1 and θ2.
Initially model selects θ1 and θ2 values randomly and then iteratively update these value in
order to minimize the cost function until it reaches the minimum. By the time model
achieves the minimum cost function, it will have the best θ1 and θ2 values. Using these
finally updated values of θ1 and θ2 in the hypothesis equation of linear equation, model
predicts the value of x in the best manner it can.
Gradient Descent in Linear Regression
(con’t)
How θ1 and θ2 values get updated ?
o Linear Regression Cost Function:
Gradient Descent in Linear Regression
(con’t)
How θ1 and θ2 values get updated ?
o Gradient Descent Algorithm For Linear Regression
Gradient Descent in Linear Regression
(con’t)
How θ1 and θ2 values get updated ?
o Gradient Descent Algorithm For Linear
Regression
1. If we choose α to be very large, Gradient Descent can overshoot the minimum. It may
fail to converge or even diverge.
Gradient Descent in Linear Regression
(con’t)
The choice of correct learning rate is very important as it ensures that Gradient
Descent converges in a reasonable time.
2. If we choose α to be very small, Gradient Descent will take small steps to reach local
minima and will take a longer time to reach minima.
Note : For linear regression Cost Function graph is always convex shaped.
Example for Linear Regression working
Suppose we are given a dataset
o Given is a Work vs Experience dataset of
a company and the task is to predict the
salary of a employee based on his / her
work experience.
o Our aims to explain how in reality Linear
regression mathematically works when
we use a pre-defined function to perform
prediction task.
o Let us explore how the stuff works when
Linear Regression algorithm gets trained.
Example for Linear Regression working
(con’t)
Iteration 1 : In the start , θ0 and θ1 values are randomly chosen.
Let us suppose, θ0 = 0 and θ1 = 0 .
o Predicted values after iteration 1 with Linear regression hypothesis.
Example for Linear Regression working
(con’t)
o Cost Function – Error
Example for Linear Regression working
(con’t)
o Gradient Descent – Updating θ0 value
• Here, j = 0
Example for Linear Regression working
(con’t)
o Gradient Descent – Updating θ1 value
• Here, j = 1
Example for Linear Regression working
(con’t)
Iteration 2 : θ0 = 0.005 and θ1 = 0.02657
o Predicted values after iteration 1 with Linear regression hypothesis.
o Now, similar to iteration no. 1 performed above we will again calculate Cost function and update θj
values using Gradient Descent.
o We will keep on iterating until Cost function doesn’t reduce further. At that point, model achieves
best θ values. Using these θ values in the model hypothesis will give the best prediction results.
Application of Linear Regression
Machine learning
o Linear regression plays an important role in the field of artificial intelligence such as machine
learning. The linear regression algorithm is one of the fundamental supervised machine-learning
algorithms due to its relative simplicity and well-known properties.
Finance
o The capital asset pricing model uses linear regression as well as the concept of beta for analyzing and
quantifying the systematic risk of an investment. This comes directly from the beta coefficient of the
linear regression model that relates the return on the investment to the return on all risky assets.
Application of Linear Regression (con’t)
Environmental science
o Linear regression finds application in a wide range of environmental science applications. In Canada,
the Environmental Effects Monitoring Program uses statistical analyses on fish and benthic surveys to
measure the effects of pulp mill or metal mine effluent on the aquatic ecosystem.
Economics
o Linear regression is the predominant empirical tool in economics. For example, it is used to predict
consumption spending, fixed investment spending, inventory investment, purchases of a country's
exports, spending on imports, the demand to hold liquid assets, labor demand, and labor supply.
Application of Linear Regression (con’t)
Trend line
o A trend line represents a trend, the long-term movement in time series data after other components
have been accounted for. It tells whether a particular data set (say GDP, oil prices or stock prices)
have increased or decreased over the period of time.
Epidemiology
o Early evidence relating tobacco smoking to mortality and morbidity came from observational studies
employing regression analysis. In order to reduce spurious correlations when analyzing observational
data, researchers usually include several variables in their regression models in addition to the
variable of primary interest.
Conclusion
Linear regression is one of the most common machine learning
processes in the world and it helps prepare businesses in a volatile and
dynamic environment.