All right.
And now time for the little extra bonus.
Let's plot the decision tree.
So in order to have the best interpretation, we are going to remove
the feature scaling.
And to do this we're going to clear everything and re-execute the code.
But without features scaling. So let's do this.
We're going to clear the data here by clicking on this button here.
And yes then clear the plots here. Yes.
And then clear the console as well by typing Ctrl L.
Here we go. All right.
Now everything is clear.
We can re-execute the whole script.
So let's do it step by step.
We're first going to take all the pre-processing step
but without the feature scaling here.
As you can see I'm not selecting this.
All right.
So now command and control plus enter to execute.
All good.
And now you can see that if we go to our data set training
set and test set you can see that the features are no longer scaled.
All right so for example in the training set we have the real age.
I mean with their real values and the real estimated salaries the real values okay.
So nothing scaled.
Now let's select this to fit the decision tree classifier to the training set.
So command and control plus enter to execute.
Here we go. Now it's fitted.
By the way I'm just going to replace this by
decision tree
classification.
All right.
Which we are really interested in right now is to plot the decision tree.
So we're going to add a new section here below.
And I'm going to call this section plotting
the Decision Tree.
And as I
told you in the Python tutorial this is going to take two lines.
This is very simple.
So let's just do it.
It's going to be very quick okay.
And besides the two lines that we need to write could not be more simple.
Because indeed what we need to type here is plot.
And then in parenthesis classifier
because you know the classifier here is the classifier that we created here
in this part using the r part function of the R library.
And that's all we just need to type plot classifier.
And that will plot the tree.
But without the labels without the conditions written explicitly.
So in order to add these conditions written explicitly,
we just need to add below text
classifier.
Here we go. And now it's ready.
Isn't that simple? There's only two lines.
We'll plot an interpretable decision tree.
Let's check it out.
I'm going to select all this and press
Command and Control plus enter to execute.
And here is the tree.
So as you can see we have at each
split the condition that is generating the splits.
So for example the first split is made
based upon the condition age lower than 44.5 years old.
So that means that if the user is below 44.5 years old,
he will go to this subcategory after the split.
And if the user is older than 44.5 years old,
he will end up in this subcategory of this split.
And then we have some new conditions.
So here and you condition on the other independent variable.
The estimated salary in this condition is estimated
salary below $90,000.
So what that means is that if the user is younger than 44.5 years old
and has an estimated salary below $90,000, then according to our decision tree
classifier, this user won't buy the SUV because the result here is zero.
And if the user is younger than 44.5
years old and has an estimated salary over
$90,000, then according to our decision tree classifier,
this user will buy the SUV because the result here is one.
Okay.
And if we go to the other side of the tree,
well, this other side of the tree first contains all the users.
There are older than 44.5 years old.
And then we have some new conditions generating new splits.
So another condition on the age here,
then another condition on the estimated salary.
And then again another condition on the estimated salary and following yes or no.
This conditions we end up in some final categories.
The final nodes of the decision tree, where the user is predicted
not to buy the SUV for this node and predicted to buy the SUV
for this node and this node and this node.
Okay, so that was worth looking at this.
We sort of explored this decision tree classifier behind the scenes.
And what's important to understand now when you are using decision trees
is that a big advantage of this classifier is that we can have
these very interpretable results.
Because here on this decision tree plot, we can see everything that's happening.
We can see how the decision tree decides
whether a user will be predicted to not buy the SUV or to buy the SUV.
We clearly see the whole thinking process of the decision tree, and in some way,
we saw how it learned from the data
how to classify each of our user of the social network.
All right.
So I look forward to seeing you in the next section about Random Forest.
We will implement Random Forest on Python in R,
and I can't wait to show you the final graphic results.
Until next time, enjoy machine learning.