All righty.
Now we've covered mean absolute error.
We're going to have a look at Main squared error here actually and make a little heading as usual because
we're keeping our notebook nice and clean.
I mean squared error.
Wonderful.
And then we're going to go means squared error.
Now you might.
Based off what we've looked at with mean absolute error you might be able to deduce how we might calculate
means squared error if not again perfectly fine so if we come down here from that skyline dot matrix
import mean squared error wonderful.
And so we're going to do it basically in the exact same way.
So MSE equals mean squared error except this time instead of using absolute we're going to be using
squared then we're going to take the Y test labels and because we've already made predictions up here
why spreads.
We could make them again but we might just reuse values here.
Why spreads.
Actually for completeness what we might do is just the Y spreads equals model not predict and we're
predicting on The X test data because we want to compare our predictions to the Y test data.
They're going to have look at MSA nine point two for two.
Mm hmm.
It's a little bit higher than what we got with mean absolute error.
Well that's because MSE or main square I should put MSA in here right.
Because there's so many acronyms these days MSE will always be higher than mean absolute error because
it squares the errors rather than only taking the absolute difference into account.
So if we come up here and have a look this data frame would be the exact same here.
So what mean absolute error does is it takes these values and it turns negatives into positive adds
them all up and then finds the average over what means squared error does is it takes these values squares
them then adds them all up and then finds the average hence the main squared error.
So that's why the squaring part squaring these numbers will lead to a higher number here.
Actually we might just do it.
So let's see if we can calculate MSE by hand.
And this is dangerous right we're going off the record here.
Calculate MSA by hand.
So all we have to do is take the differences here so actually def differences we need a square that
actually might do here.
So.
Is it empty square empty askew square dance differences and then should we add a called the main on
that actually.
Let's put that in brackets can we do that don't mean right.
Squared equals that what does squared look like OK.
So this is going to take this column here and squared now to calculate the MSE.
We just need to take the main of squared beautiful.
There we go.
See that's how we calculate the main squared error.
That's it right.
We've covered means quite ere we covered mean absolute error and we covered square.
Now the next logical question is and even if you aren't asking it is which regression evaluation metric
should you use.
So we look here we'll come back to the KEYNOTE so our squared is similar to accuracy right.
It gives you a quick indication of how well your model might be doing.
Generally the closer you are squared value or coefficient of determination value is to 1 the better
the model.
But as we've seen before us square doesn't really tell us exactly how wrong our model is in terms of
how far off each prediction is for that mean absolute error gives a better indication of how far off
each of your model's predictions are on average.
So that's when we saw this one here.
Right.
This is how we saw on average each of our models predictions is about two point one two away from what
it actually should be.
Whether that's positive or negative.
And so we come back here now can get a bit confusing which to use between mean absolute error and mean
squared error.
Well because of the way main squared error is calculated.
We saw that by calculating it by hand.
We squared the differences and then took the main right instead of just taking the absolute differences
because of how MSE is calculated squaring the differences between predicted values and actual values.
It amplifies larger differences.
So you could imagine if we had a difference of say 10 and we squared that right.
That's going to be now a difference of 100 and we're taking the average of that.
So let's say we're predicting the value of houses which we are.
You want to pay more attention to mean absolute error when being ten thousand dollars off is only twice
as bad as being 5000 dollars off.
So that makes sense right.
But pay attention more to means squared error when being ten thousand dollars off is more than twice
as bad as being five thousand dollars off.
You might think well it's not really if I double 5000 dollars to ten thousand dollars.
So this is kind of another way of saying is that when bigger errors are bigger than smaller errors.
Right.
So if we're ten thousand dollars off and that's way worse than being 5000 dollars off we want to look
more to means squared error.
Long story short you want to a little tidbit here is for regression models you want to minimize mean
squared error and minimize mean absolute era while maximizing r squared right.
So does that make sense.
Minimize mean absolute error minimize means squared error while maximizing R squared.
Now that we've covered a handful of some of the most useful in common regression metrics we come back
here.
We see that there's still a fair few more that we could have done right.
So that's a little challenge to you is to dive into model evaluation metrics.
But the ones we've gone through a more than enough to get started you might be thinking hold on.
We haven't even used the scoring parameter which is what we talked about five or six videos ago.
Well now that we've covered some of the as I said some of the most common and useful regression and
classification metrics we can finally take a look at the scoring parameter which is what we'll do in
the next couple of videos.