Okay, so let's input the arguments.
As you remember, the first argument
was the matrix of features the matrix of independent variables.
And that is training set excluding the last column which has index three.
Because as you remember in the training set
we have the first two columns which are the independent variables
age and estimated salary was therefore indexes one and two.
And we have the third column indexed by three
which is our dependent variable vector purchased.
So here minus three.
Then what was the next argument.
The next argument was why the dependent variable vector.
And then here will take training set.
And let's pick it this way to specify the name of the independent variable.
$2 here. And purchased.
Purchased is the name of our dependent variable column.
All right. So we almost have everything we need.
The last thing we need now is of course the number of trees.
And that is entry equals ten.
You can play around with the entry argument.
You can choose many more trees in the forest.
You'll observe some interesting results.
That's interesting to see what different teams of trees can do
to predict the response of your users in the social network,
whether they buy yes or no. The SUV.
But if you do this, make sure to pay attention to overfitting,
which you want to avoid.
You don't want to overfit the random forest classifier to the training set,
because if you do this, then it might make some poor predictions on a new set.
You can actually check it out with the test set, but here we'll
choose ten trees and we'll see what happens.
All right.
So actually we're done with the templates.
We changed everything we had to change.
And now we can just,
you know select everything and execute to make everything ready.
You can actually take some coffee or tea and you can just select
everything and execute to watch the results.
But let's rather do it step by step.
We'll just do the first pre-processing step all in once here.
So I just selected the pre-processing phase.
And now I'll press Command and Control.
Press enter to execute.
All right all good.
We have our data set, our training set and our test set.
So everything looks fine.
We have 400 observations in total, 300 observations
that went into the training set and 100 observations that went into the test set.
As you can see, the training set and the test set are scaled
because in the end, we are plotting some graphic results with a resolution of 0.01.
So in order for our code to execute faster and not actually break our code,
we need to apply feature scaling to our training set and our test set.
Otherwise, we wouldn't need to do that because the random
forest classification is not based on Euclidean distances,
but it's based on, you know, conditions on the independent variables.
But because of this code here that is compute intensive,
we need to apply feature scaling so that everything is well executed.
All right. So let's do this.
Let's watch the results.
We just need to create our classifier here by executing this section.
So here I'll just do this.
All right okay.
Now let's predict the test set results.
Then we have the confusion matrix which will tell us in the flashlight
how many incorrect predictions we have.
So let's actually do it directly.
It will be faster to see how our random forest classifier did
well on the predictions.
So let's execute this.
And now let's enter
CM here in the console press enter.
And here we have our confusion matrix
okay we have seven plus ten equals 17 incorrect predictions.
Well that's not too bad.
Just for fun let's let's just pick another number of trees.
Like for example let's pick 500 trees.
500 trees is a lot.
That's a really a big army of trees to make some predictions.
And now, just for fun, let's take this.
I don't need to include this because my library was
already selected from the previous execution of this code section here.
So let's rebuild a new classifier with 500 trees.
And now let's look at the confusion matrix.
But before let's build our vector of prediction.
Because right now
the y vector of prediction is the one given by the random forest with ten trees.
So let's re-execute this. All right.
Now we have y pred as the vector of predictions
predicted by the random forest with 500 trees.
And now let's look at the matrix of predictions.
Remember, with ten trees we had 17 incorrect predictions.
And now let's see.
Select execute CM enter.
And now we have 15 incorrect predictions.
Great.
We invested 490 more trees to win two correct predictions.
So definitely that means that there are a lot of and useful trees in the team.
Okay.
So as you want let's maybe go back to ten trees here
because obviously 500 trees is not very useful.
All right.
So I'll just take that again.
That as well and that as well.
All right.
And now let's look at the training set results.
So everything is fine here.
We changed the title here with random forest classification.
So it's all good.
We are ready to look at the graphic result.
And by the way you can pause on the video now and try to guess what
you're about to see.
Try to guess the shape of the prediction regions and of the prediction boundary.
If you understood correctly the decision trees,
then you would have no problem guessing what's about to happen.
All right.
So I'm going to execute right now command and control
plus enter to execute and show time.
All right. Wow. That's quite something here.
So the points here are the real observation points.
There is the real users of the social network.
And then we have the regions here the red region and the green region
which are the prediction regions.
The red region is the region where our random forest classifier
predicts that the user doesn't buy the SUV, and the green region
where a random forest classifier predicts that the user buys the SUV.