The Prediction Power of Machine Learning
The first
subcategory of supervised machine learning is regression. This model only
uses a simple best fit line for the dataset so that the ordinary least squares
value is minimum. Ordinary Least Square value
indicate the sum of squared value of difference between actual and the
predicted value.
OLS = ∑ ( Yactual – Ypredicted
)2
Each
regression line has a unique slope and intercept and one and only one line can
fit a dataset. These type of models are used to predict the future outcomes on
the basis of unique correlation between independent variables also called as regressors and dependent variable. The
major categories of Regression are as follows :
- Simple Linear Regression
- Multiple Linear Regression
- Polynomial Regression
- Decision Tree Regression
- Random Forest Regression
The
easiest of them all is the Simple Linear Regression. This model can be
implemented best when the independent variable depends only on one regressor.
It is called a linear regression as the relation between the dependent variable
and regressors can be expressed as a linear equation containing only one
coefficient and a constant. We calculate the value of these coefficient and
constant so that there is only one equation which fits the business problem.
y0 = b0
+ b1x1
This
equation denotes a line of slope b1 and intercept equal to y0
which is the locus of all the predicted values and the Ordinary Least Square
value is min. for this line.
GitHub Link : https://github.com/raghav9-97/Machine-Learning-Odyssey/blob/master/Simple_Linear_Regression.ipynb
The problem arises when there are a number of
regressors in the business problem. This
problem is solved by our second regression model i.e. Multiple Linear
Regression. This model can consume a large number of regressors and hence is
widely used. The equation for this model contains a large number of terms and
one constant term.
y0 = b0 + b1x1
+ b2x2 + b3x3 + ……..bnxn
If in the
these regressors it contains a categorical variable we have to use LabelEncoder
and OneHotEncoder to encode it into dummy variables. Now here comes the trap
also known as Dummy Variable Trap.
After encoding the category variable into dummy variable we have to omit one
variable to escape from the dummy variable trap.
The default case is when the equation contains
the constant term and the all the dummy variables except one. The constant term
compensates the missing variable. In actual practice if a categorical variable
is divided into two dummy variables D1 and D2 then D2
= D1 – 1.
This fact
is is due to the reason as when D1 is unity the second one is zero
and vice versa and this property when a variable or regressor determines other
it is known as Multicollinearity. The
constant, the first coefficient and the second coefficient cannot coexist
because it records for redundancy of information.
The
compiler cannot understand clearly the effect of first dummy variable and
second variable distinctively. Therefore it is inappropriate to use all of them
at once.
There are
multiple methods to build a model if the number of regressors are more than
one. The various methods to build a model are :
- All In
- Backward Elimination
- Forward Elimination
- Bidirectional Elimination
- Score Comparison
PRO TIP : In Multiple Linear Regression we
have to take care of the constant term explicitly because the Statsmodel class
used for building the model does not contain constant term by default. So we
have to explicitly add a column of ones which is treated as a constant in the
equation.
GitHub Link : https://github.com/raghav9-97/Machine-Learning-Odyssey/blob/master/Multiple%20Linear%20Regression.ipynb
If the
observation points are non linear and follows a parabolic nature then we use
Polynomial Regression. The Polynomial Regression is Linear Regression Model
fitted on the polynomial terms of the dataset. It is a special case of Multiple
Regression where each higher degree term is a polynomial term of only one
regressor. The polynomial regression equation looks something like this
y0
= b0 + b1x1 + b2x12
+ b3x13 + ……… bnxn
The
polynomial regression curve looks like a parabolic curve and fits the non
linear data well.
The
important aspect of all the models discussed so far is that they all are linear
and continuous machine learning models.
GitHub Link : https://github.com/raghav9-97/Machine-Learning-Odyssey/blob/master/Polynomial%20Regression.ipynb
Now we will discuss two most important
non – linear and Non continuous Models. The first one of them is Decision Tree
Regression and the second one and most powerful of them all Random Forest
Regression.
The
Decision Tree Regression model is used when the dataset is too messy to handle
and none of the learnt models can provide a solution. It works on the principle
of splitting the dataset into leaves on the basis of Information Entropy i.e. the splits will increase the information
content in the dataset. The final splits are called terminal leaves and the new
incoming data point is assigned the average value of the split in which it lies.
This type
of tree is basically a Decision Tree where to assign the value of the new data
point we have to traverse through all the conditional statements to arrive at a
value to be assigned.
The next
and the last model is Random Forest Regression which is an Ensemble Learning
model which means combining multiple machine learning models of same or
different types to enhance the prediction power. We will later learn other
Ensemble model like XGBoost in which we combine different models together. The
advantage of using Ensemble modelling is that if one model is affected by any
outlier or any error it doesn’t have a negative effect on total outcome.
Random
Forest Regression arbitrarily chooses K data points from dataset and implement
decision tree on it and then repeat the process N times to obtain N decision
trees. The value of oncoming data point is calculated as the average across all
the decision trees and hence a good predicted value is seen as outcome.
Decision Tree GitHub Link : https://github.com/raghav9-97/Machine-Learning-Odyssey/blob/master/Decision%20Tree%20Regression.ipynb
Random Forest GitHub Link : https://github.com/raghav9-97/Machine-Learning-Odyssey/blob/master/Random%20Forest%20Regression.ipynb
So that’s
it for this post, I know the post was so long but it deserved to be as it covered all the concepts of Regression. In the next post we will see some Regression Models Evaluation Parameters which help us to optimize our model statistically.
I am overwhelmed by your response towards the blog and from now onwards I will post regularly and you can expect new posts on every Tuesday and Friday. There are some upcoming posts on advanced toolbox
like TensorFlow etc.
So Stay
Tuned……
Comments
Post a Comment