Hello and welcome back.
In the previous lesson, we have learnt about R-squared and adjusted R-squared metrics, and in this
lesson we are going to see m e r s e R-squared and adjusted R-squared in code.
So without any further ado, let us get right into our Jupiter notebook.
We have the same notebook as we discussed in the cross-validation lesson.
But here we have added quote of our metrics.
Nothing makes writing mathematical functions in Python really easy.
Let us first look into R and R and S.
E takes in two parameters actual values and the predicted values.
We first subtract the actual predicted values, squared them and do a sum to the whole vector.
We divide it with the length of widest to find the average and return the value by a square root.
Next we have is the.
This function also takes an actual and predicted values, finds the sum of absolute difference between
the both averages and returns.
The value.
It is simple isn't it.
Now let us look into the squared function.
First we find the S.R., which is the main squared difference between actual and predicted values.
Next, we find the SSD, which is the mean squared difference between actual and average value, and
we return one minus R upon SSD, which is exactly the same as the formula.
Finally, we have adjusted R-squared function.
This function takes in actual values, predicted values and number of features.
The number of features here are used as Benanti.
The numerator is one minus R-squared in two and minus one there and is the length of widest the denominator
is and minus K minus one.
Here is our third parameter and underscore features.
We divide numerator denominator and subtract that from one minus, which is our adjusted R square formula.
Now let us use all of these metrics to evaluate our giffels quality.
Here we are iterating on Folt indexes.
We create our training and testing set.
Every time we sit on the training data, we generate a vibrant which are the predictions of our testing
set, we now send the testing tables and predictions to our functions that we have created on the bench
the values into lists to ritualize them.
Later here in the adjusted R-squared, we pass in the number of columns as the third parameter.
Now, let us plot the scores.
We have our C and an E in the first two graphs, we see that M E is always less than R.
S e and both follow the same trend as in the back backend.
We are finding the difference between actual and predicted.
In both the cases.
Our models average are S e is zero point six five and and E is zero point for one.
Please note that we get less R.
S e because we have scaled down our target using box Cox.
Let us move on to R-squared and adjusted R Square.
This seems interesting here or square and adjusted R Square.
Follow an exact same trend.
In all the faults, the average R squared is zero point seven six six and average adjusted R squared
is zero point seven six zero.
They are very close, which means there is very less penalizing effect on adjusted R Square and all
the features of the dataset are important in explaining the targeted variance.
Well, I recommend you to go through the Jupiter notebook provided for this lesson and metric formulas
to understand the concept more effectively.
And now it's time for a quick recap in this lesson.
We have programmed the Ford Matrix from scratch using numpty and interpret the results accordingly.
In the next lesson, we are going to learn how to apply linear regression in real time predictions so
that happy machine learning.