Everyone and welcome to Coding Task Number five.
In this task, we are going to train and test our linear regression model insight cycle, learn and
please note that stage maker built in algorithms such as linear learner will not going to be used in
today's project.
We are going to cover that tomorrow to solve multiple linear regression problems.
But for today, let's go ahead and just see how we can implement psychic learning or scalar library
to solve our problem.
If you guys recall in the previous task, we covered our practice opportunity.
Number four, we learned how to perform train to split without specifying the test size.
And we found that essentially the default value is 25% will be allocated for testing and 75% will be
allocated for training.
Okay.
So what I wanted to do right now is I wanted to import our linear regression.
So I'm going to say from scalar linear model, I'm going to import linear regression.
And then from metrics, from scalar metrics, I'm going to imported the mean squared error and the accuracy
score.
And then after I put it here, my linear regression class, I'm going to instantiate an object, I'm
going to call it regression model scalar out of my class.
So I'm going to see regression model X equals to linear regression.
And then I'm going to apply the fit method on my object, pass it along my training data, which is
my extreme and white tree.
Please note that this is exactly the same as we have done before, so it doesn't really matter if you're
doing simple linear regression or multiple linear regression.
It's pretty much the same.
All what you need to do is that's just the dimensions of extreme and white train will be different essentially.
So in multiple linear regression right now, Extreme has a lot more features compared to that basic,
simple example that we covered in yesterday and the day before as well.
Shifting into here we go, let's go ahead and score that model.
So I'm going to grab my regression model escalation and then I'm going to save that score, pass it
along my testing data, which is again data that the model has never seen before during training.
And here we go.
We have been able to achieve almost 79%, I would say accuracy, which is pretty okay, I would say,
and I can go ahead and pass it along my x test.
Apply the predict method on my object to generate y predict.
These are essentially the predictions coming out from my model.
When I see predictions, that means 12061.
This is simply the expected and SRP predicted an SRP for the first testing data point.
This is the predicted price as well from the second data point and so on.
So these are all the predictions coming out from my model.
If I wanted to assess the performance of my trained model, what I could do is they can go ahead and
actually calculate all the various KPIs.
What keep for indicators that I've already covered in the previous couple of lectures.
First, I'm going to obtain the number of independent variable.
So I'm going to say Run it again here.
So I have 13, I'm going to obtain the end, which is the test, which is one or seven.
And then I'm going to go ahead here and then I'm going to calculate the autumns e or the root mean squared
error, the MSI MP R squared and adjusted R squared.
And I assume all of you guys are familiar with all these different metrics by now.
So ultimately I'm going to essentially compare the white test, which is the ground truth data.
This is again the testing data.
With the predictions coming out from my model, I'm going to obtain the mean squared error and then
I'm going to square through that and then I'm going to put in the float essentially kind of change the
data type for it going.
I'm going to calculate the mean squared error here.
It's going to be my MSI.
I'm going to also calculate the mean absolute error.
And I'm also going to calculate the coefficient of determination which is R squared basically.
Luckily I can just say R2 square, which is one of the metrics that are imported here from Scalar.
I don't need to go and substitute in the equation essentially so I can say r squared r, so r2 score
pass along my white test and y predict that's going to create my coefficient of determination.
And then I can also go ahead and calculate the adjusted R squared and that is going to be one minus
one minus R squared times n minus one divided by n, minus k, minus one shift and enter.
And here we go.
We have been able to achieve coefficient of determination of around 0.798, which is P okay.
I would say and I can here go ahead and plot a scatterplot that can show me the white test versus white
predict.
So that's an.
She was the model is predicting versus the actual ground truth data.
As long as I have an AK 45 degree angle line, that means the model predictions matched what actually
happened in real life, and that's it.
That's simply all I have for this task.
I hope you guys enjoyed it.
In the next practice opportunity.
And that is going to be my last practice opportunity for today.
I'm going to ask you guys to train a different type of an aggressor regression models and as well evaluate
its performance.
So please stay tuned.
Best of luck and I'll see you guys in the next task.