Module5
Module5
Types of Regression
Linear regression is one of the simplest and most widely used statistical
models. This assumes that there is a linear relationship between the
independent and dependent variables. This means that the change in the
dependent variable is proportional to the change in the independent
variables. For example predicting the price of a house based on its size.
3. Polynomial Regression
Ridge & lasso regression are regularized versions of linear regression that
help avoid overfitting by penalizing large coefficients. When there’s a risk
1
of overfitting due to too many features we use these type of regression
algorithms.
Applications of Regression
2
Forecasting trends: Model to forecast the sales of a product based
on historical sales data.
Advantages of Regression
Robust to outliers.
Disadvantages of Regression
Assumes linearity.
Both approaches require labeled data for training but differ in their
objectives—classification aims to find decision boundaries that separate
classes, whereas regression focuses on finding the best-fitting line to
predict numerical outcomes. Understanding these distinctions helps in
selecting the right approach for specific machine learning tasks.
3
For example, it can determine whether an email is spam or not, classify
images as “cat” or “dog,” or predict weather conditions like “sunny,”
“rainy,” or “cloudy.” with decision boundary and regression models are
used to predict house prices based on features like size and location, or
forecast stock prices over time with straight fit line.
4
During training classifier learns to partition the feature space by
finding a boundary that minimizes classification errors.
The decision boundary is not inherent to the training data but rather
depends on the classifier used; we will understand more about classifiers
in next chapter.
5
The plot demonstrates Regression, where both Linear and Polynomial
models are used to predict continuous target values based on the input
feature, in contrast to Classification, which would create decision
boundaries to separate discrete classes.
Classification Algorithms
Logistic Regression
Decision Tree
Random Forest
K – Nearest Neighbors
Naive Bayes
Regression Algorithms
Lasso Regression
Ridge Regression
XGBoost Regressor
LGBM Regressor
6
Feature Classification Regression
To predict an exact
To predict which category
Goal numerical value based on
a data point belongs to.
input data.
Linear Regression,
Logistic regression,
Common Polynomial Regression,
Decision trees, Support
algorithms Decision Trees (with
Vector Machines (SVM)
regression objective).
7
On the other hand, regression trees are utilized when dealing with
continuous response variables. For instance, if the response variable
represents continuous values like the price of an object or the
temperature for the day, a regression tree is the appropriate choice.
8
Our primary objective while using linear regression is to locate the best-fit
line, which implies that the error between the predicted and actual values
should be kept to a minimum. There will be the least error in the best-fit
line.
The best Fit Line equation provides a straight line that represents the
relationship between the dependent and independent variables. The slope
of the line indicates how much the dependent variable changes for a unit
change in the independent variable(s).
Assumptions are:
9
the independent variable lead to proportional changes in the
dependent variable.
10
Types of Linear Regression
β0 is the intercept
β1 is the slope
11
the value of the dependent variable for another
observation. If the observations are not independent, then
linear regression will not be an accurate model.
3. Homoscedasticity: Across all levels of the independent
variable(s), the variance of the errors is constant. This
indicates that the amount of the independent variable(s)
has no impact on the variance of the errors. If the
variance of the residuals is not constant, then linear
regression will not be an accurate model
12
and corresponding sales figures analysts develop a regression
model that tells the relationship between these variables. For
instance if the analysis reveals that for every additional dollar spent
on advertising sales increase by $10. This predictive capability
enables companies to optimize their advertising strategies and
allocate resources effectively.
The goal of the algorithm is to find the best Fit Line equation that
can predict the values based on the independent variables.
In regression set of records are present with X and Y values and these
values are used to learn a function so if you want to predict Y from an
unknown X this learned function can be used. In regression we have to
find the value of Y, So, a function is required that predicts continuous Y in
the case of regression given X as independent features.
For Multiple Linear Regression, all four of the assumptions from Simple
Linear Regression apply. In addition to this, below are few more:
13
there is no interaction between variables in their effects on the
dependent variable.
Multicollinearity
14
Agricultural Yield Prediction: Farmers can use MLR to estimate
crop yields based on several variables like rainfall, temperature, soil
quality and fertilizer usage. This information helps in planning
agricultural practices for optimal productivity
Now that we have understood about linear regression, its assumption and
its type now we will learn how to make a linear regression model.
As we have discussed earlier about best fit line in linear regression, its not
easy to get it easily in real life cases so we need to calculate errors that
affects it. These errors need to be calculated to mitigate them. The
difference between the predicted value Y^ Y^ and the true value Y and
it is called cost function or the loss function.
15
A linear regression model can be trained using the optimization
algorithm gradient descent by iteratively modifying the model’s
parameters to reduce the mean squared error (MSE) of the model on a
training dataset. To update θ1 and θ2 values in order to reduce the Cost
function (minimizing RMSE value) and achieve the best-fit line the model
uses Gradient Descent. The idea is to start with random θ1 and θ2 values
and then iteratively update the values, reaching minimum cost.
16
Finding the coefficients of a linear equation that best fits the training data
is the objective of linear regression. By moving in the direction of the
Mean Squared Error negative gradient with respect to the coefficients, the
coefficients can be changed. And the respective intercept and coefficient
of X will be if α α is the learning rate.
17
valuation Metrics for Linear Regression
Here,
Here,
18
n is the number of observations
The square root of the residuals’ variance is the Root Mean Squared Error.
It describes how well the observed data points match the expected
values, or the model’s absolute fit to the data.
19
R squared metric is a measure of the proportion of variance in the
dependent variable that is explained the independent variables in the
model.
Here,
R2 is coeeficient of determination
20
Regularization Techniques for Linear Models
the first term is the least squares loss, representing the squared
difference between predicted and actual values.
the first term is the least squares loss, representing the squared
difference between predicted and actual values.
21
α controls the mix between L1 and L2 regularization.
For example, we have two classes Class 0 and Class 1 if the value of the
logistic function for an input is greater than 0.5 (threshold value) then it
belongs to Class 1 otherwise it belongs to Class 0. It’s referred to as
regression because it is the extension of linear regression but is mainly
used for classification problems.
Key Points:
22
2. Multinomial: In multinomial Logistic regression, there can be 3 or
more possible unordered types of the dependent variable, such as
“cat”, “dogs”, or “sheep”
So far, we’ve covered the basics of logistic regression, but now let’s focus
on the most important function that forms the core of logistic regression.
It maps any real value into another value within a range of 0 and 1.
The value of the logistic regression must be between 0 and 1, which
cannot go beyond this limit, so it forms a curve like the “S” form.
24
Equation of Logistic Regression:
25
Likelihood Function for Logistic Regression
26
Terminologies involved in Logistic Regression
27
value between 0 and 1, which represents the likelihood of the
dependent variable being 1 or 0.
Target variable can have 3 or more possible types which are not ordered
(i.e. types have no quantitative significance) like “disease A” vs
“disease B” vs “disease C”.
28
So far, we’ve covered the implementation of logistic regression. Now, let’s
dive into the evaluation of logistic regression and understand why it’s
important
We can evaluate the logistic regression model using the following metrics:
29
Linear Regression Logistic Regression
Maximum likelihood
Least square estimation
estimation method is
method is used for
used for Estimation of
estimation of accuracy.
accuracy.
It required linear
relationship between It not required linear
dependent and relationship.
independent variables.
30