‫As you might have guessed, the predict method can be used on regression algorithms as well.
‫So let's try that out.
‫We use the same data set that we use before, so go predict can also be used for regression models.
‫Turn that into markdown and let's have a look at our housing data frame.
‫Remind ourselves housing DF Wonderful.
‫So here we've got some features that we've seen these before that we're trying to predict a target value.
‫So let's just write out.
‫We could go up and copy the code from before, but let's have a little bit of practice.
‫So let's get our ensemble algorithm.
‫We're going to use the random forest regression because we're using trying to predict a number that's
‫a regression problem.
‫We'll set the random seed just as what we set up before we're going to create the data.
‫So X is equal to housing DF dot drop.
‫We'll get rid of the target variable because we want to use all of the features here to predict the
‫target.
‫So axis equals one and this is very common of what you'll have to do as you've you've seen in the video
‫so far in future videos and future projects is getting your data into features and labels.
‫So we'll create the labels then that's the target we're going to now split into train and test sets,
‫so split into training and test sets.
‫We'll have x train, x test, y, train, y test and then we'll have train test split and that can be
‫x, y test size equals 0.2.
‫And then we'll create the model instance which will be model equals random forest re aggressor.
‫What help if I could spell and an estimate us which is the number.
‫Remember the random forest if you've DivX if you've dove into some random forest documentation and estimate
‫us a set by so I could learn this to be 100 by default, but you can put this up to 1000, you can put
‫this to 200, you can put this to ten.
‫And with the random forest, again, that just means how many little models are we using to create one
‫ensemble model to predict on our data?
‫So I'm just going to leave it as the default, which will be an estimate as equals 100.
‫That's fine.
‫And that's a beauty of SQ lone is that we're going to be able to use the predictive method on a regression
‫algorithm and many of the algorithms and estimate is within.
‫So I get learn already have great default parameters.
‫So try them out with the defaults and if they don't work very well, you can always alter the parameters
‫in here.
‫I'll let you dive into the documentation to see what you might change there.
‫Let's get out of that and make predictions.
‫Y Pres How do you think we could use our model to make predictions?
‫Y pred equals model predict oh, just like that on the test data set.
‫Let's see what happens.
‫Oh what did we get.
‫A not fitted error.
‫What do you think?
‫That's from this random forest regress?
‫The instance is not fitted yet.
‫Call fit.
‫Oh, of course.
‫We can't make predictions just yet.
‫What do we have to do?
‫Well, we've instantiated a model, but we haven't fit it to the data.
‫So thank us, Caroline, for that.
‫Let's go fit the model.
‫To the data and we'll go model fit.
‫What are we going to fit it on?
‫The training features and the training labels.
‫And now we should be able to make predictions.
‫Wait a few seconds, because housing DF remember is 20,000 rows.
‫Random forest regress is building 100 little models.
‫Oh, beautiful.
‫Let's now have a look at why Preds.
‫Why Preds first ten.
‫Wonderful.
‫Are they in the same?
‫So here's another thing about machine learning, right?
‫All comparisons when we trying to evaluate these predictions because that's what we want to do next.
‫We want to evaluate these predictions.
‫Are they in the same format as our target variable because we want to compare apples to apples.
‫So our target variable is 4.5, but this is in hundreds of thousands.
‫So our predictions, we want them to be in the same format as the target.
‫So let's have a look at some of the the first ten target variables why test we might turn that into
‫that shuffled so we might turn that into an MP array.
‫Sorry that's already the that's a series.
‫So what we might do is turn this into an array.
‫There we go.
‫Oh I don't think we need those in a brackets, actually.
‫Learning on the fly here.
‫Okay, beautiful.
‫So this looks quite similar to these.
‫Now we're going to have a look at more regression evaluation metrics in a second, but how might we
‫evaluate our model?
‫Our model's predictions, that is on the test data set.
‫So if you made some predictions on the test data set, how can we how do you think we could evaluate
‫these?
‫Well, we can compare them because let's have a look at length of why Preds, why Preds and length of
‫why test.
‫So that means there's one value for every test value.
‫There's one prediction our model has made for every test value.
‫So.
‫Hmm.
‫What?
‫I want you to have a look up before we get to the evaluation metrics is just have a look.
‫Regression evaluation metrics.
‫Just have a look at that.
‫You could even go.
‫There we go.
‫Regression metrics for machine learning or scoreline regression evaluation.
‫Well, metrics and scoring.
‫Beautiful.
‫We're going to have a look at this in a moment, but I'll just give you a little hint.
‫I would like you to start challenging yourself with these things.
‫So you're going to notice a little trend with all these videos coming up is I'm going to challenge you
‫before the next video.
‫So let's have a think about how we might compare these so we could if this value is the same as this
‫file, we could minus it, and then we could do the same with this.
‫Minus that from that, minus that from that, that, from that.
‫And do that for the whole entire array and then maybe take the average of all those differences.
‫Now what we've just described there is mean absolute error.
‫So let's have a look at that.
‫The average difference between the predicted values and the true values.
‫So compare the predictions to the truth.
‫We'll go from scalar matrix import mean absolute error and then mean absolute.
‫We could minus all of these by hand and then find the average.
‫But the beauty of psychic learn as you've seen, is that many important machine learning functions,
‫including models and evaluating models, are built in.
‫So let's have a look at this.
‫Oh, beautiful.
‫So what does this mean?
‫Well, because we've used mean absolute error.
‫This means that on average, mean is the same as average.
‫On average, each one of our models predictions is 0.32 different to the actual test value.
‫Now, of course, there may be some predictions that are more than this value.
‫There may be some predictions that are less than this value, worse than the Y test value or different
‫to the Y test value.
‫But let's just go back to our target variable.
‫If we have a look at let's go housing DF spreads equals Y spreads and then we go housing DF head.
‫What are we missing here?
‫Length of value does not match.
‫Oh we need the test data set you right.
‫So it's not going to really work, is it?
‫Hmm.
‫How can we compare these?
‫Let's just view the target.
‫So we're going to create let's go housing DF target.
‫We'll just view the target column.
‫So our model's predictions Y spreads are on average 0.32 different.
‫So it could be plus or minus these target values.
‫But that's how we make predictions with our cyclone estimators or models, we can use the predict function.
‫And then later on we're going to see a bit more about how we evaluate those predictions.
‫Remember, the crux of evaluation is comparing our model's predictions to what it should have predicted.
‫Now, there are many different ways to do that.
‫We're going to see that in the upcoming videos.
‫I'll see you there.