Did you figure it out.
It's okay.
You didn't.
Because we're gonna see what we can do now.
How do you predict with a regression model.
Well the great news is because of the absolute precision on it's really going to be applauded to the
socket line development team the way they've designed the library is absolutely amazing.
Right.
So predict can also be used for regression models.
So we could go back up and copy and paste our code but what we gonna do is practice a little bit more
from SDK learn that ensemble going to import random forest regress.
Because random forest is our friend and a NPR random seed because we want to make sure our results are
reproducible.
Then we're gonna go create the data.
X equals Boston D F don't drop.
Now if you want to remind yourself Boston DFA looks like this.
So remember what we're trying to do is build a model that learns of these features to predict this target
so we go here.
Boston data center dot drop we want to remove the target and we get access equals one Y equals Boston
D.
Why is the target column.
That's the labels and then we're going to go split into training and test sets x test X trying y trying
y test angles try and test split.
There we go.
Wonderful.
And now we're going to instantiate and fit model and go model equals random forest Progresso.
And you know we could even do this in one hit dot fit.
This is a pretty cool thing right.
It's called chaining.
So we've just saved ourselves a line of code.
This would usually be modeled up fit.
Actually one word.
And then what we can do is say this is going to fit the model we've seen if fit does it goes Hey find
the patterns in X train and compare them to y train and figure them out.
Now this is gonna line the patterns.
Now we want to use a pattern.
So we want to make some predictions make predictions.
And this is where the predict function comes into play.
Y reds equals model not predict x test.
So this is saying hey make some predictions on the test dataset and save it to the predictions or Y
spreads variable.
So let's do that Oh what's happened here.
We got it in here.
Check.
We're probably gonna type a number of labels for a forward is not match number of samples.
What have we done.
X train up.
This is what we mixed up we've mixed up these train test saying you're gonna get errors even though
we've talked this one line of code about 20 times in this notebook already still making errors.
Beautiful.
And again we're getting that warning an estimate is I should really just upgrade my SO I GET loan to
zero point to two so it removes that warning.
Then we go here.
Beautiful.
So now we've made some predictions and they're stored in wife reds.
So what does this look like on there's too many there.
Let's just be the verse 10.
Now let's compare this to our test label's and we want to put that in a number higher array.
So it just kind of looks a bit similar excellent.
So this is what our regression model has predicted based on the X test data that it's looked at and
this is the truth.
So what we want to do is evaluate there.
So how do you think you might evaluate a regression model trying to predict a number what you might
do is figure out how far it is away from age prediction.
So see here the first prediction is twenty three point 0 0 to the actual label is twenty three point
six this one the prediction is thirty point eight to six in the actual label is thirty two point four.
And so we could do that for each and every sample and maybe get the average.
Well that's a valuation metric called mean absolute error.
So that's what we can do.
Compare the predictions to the true so we want to go from S.K. loan metrics import mean absolute error.
Can we go there to say no typos and then I do a typo classic mean absolute error why test.
So this is saying hey exactly what we just said let's go through each and every prediction.
Right.
So why spreads and compare them to the test labels and then figure out what the difference is between.
So we do twenty three point six minus twenty three point 0 0 2 and then thirty two point four minus
thirty point eight to six etc. etc. across the entire dataset and then we'll figure out what the difference
is for each sample and then we'll animal up and then figure out the average.
So that's what mean absolute error does.
We'll do that boom.
So what this is essentially saying is that on average for every single prediction here what we're trying
to do we've trying to model that on average predicts something that is two point two.
This is this figure here or two point one two point one away from the target.
So on average it might predict 22 or 26 or 23 or 19 et cetera et cetera et cetera.
So that's not too bad right.
Two off and it may be pretty bad right.
If you wanted to be really accurate but this all depend on what kind of problem you're working with
what sort of error metric you allow or what sort of evaluation metric you allow.
Depends on the problem you're working on.
And speaking of evaluation metrics I believe that's next in what we're covering evaluating a model.
We've kind of just touched on a little bit here but we're going to go a bit more in depth in the next
section.
So what we've seen in this section is fitting a model to some training data set a.k.a. finding patterns
in data finding patterns between x and y and then using a train model using the patterns that it's learned
to make predictions on our data.
All right.
So take a little break go back through what we've done.
See if you can get a model to make some predictions and some data and then in the next section we'll
look at how we can evaluate our models.