And now let's check it out.
The model is actually ready.
We can actually replace that by decision tree
regression.
And now let's check it out and you will see
what the real decision tree regression model looks like in 1D.
So let's do it.
Let's select all this and execute.
And here it is.
That's what it looks like.
And actually
since it's a non continuous model we should even have some strict
vertical line here.
You know to represent better than non continuity.
And to do this we just need to increase the resolution.
So I'm going to put 0.01 and you'll see that
we'll get the real representation of the decision tree regression results.
So let's do it.
Here it is now almost vertical.
And that's a clear representation of the decision tree regression model.
So now let's zoom on it.
And now it makes much more sense because as Carol explained
based on the entropy and the information gain, it splits
the whole range of your independent variable into different intervals.
So here we can clearly see where the intervals are.
The first interval is from 1 to 6.5.
The second interval is from 6.5 to 8.5.
Then the third interval is from 8.5 to 9.5,
and finally the last interval from 9.5 to 10.
So there we go.
We can clearly see the intervals now.
And as Carol explained in the intuition tutorial, the decision tree regression
model is considering the average of the dependent variable values
in each of the intervals.
This one, this one, this one, and this one.
So for example,
if we consider this interval here, the average of the salaries in this interval.
Well that's very simple.
It's actually 250,000.
And so for each of the level between 6.5 and 8.5,
the salaries will be predicted to be $250,000.
So we already know what our model will predict for our 6.5 level here.
It's going to predict 250 K.
So speaking of this prediction.
And now that we get the decision tree regression graphic results very well,
let's actually check that the previous salary of this employee
that had a 6.5 level in its previous company is actually 250 K.
Let's check it out.
Let's select this line and execute.
And here it is 250,000 exactly like we predicted
because we can clearly see that on this plot.
So now we just want to say two things to conclude.
The decision tree regression model is not an interesting model in 1D,
but it can be a very interesting and very powerful model in more dimensions.
So that's why you can use this code here for your data set.
You have the code here that builds the model.
And this one here then makes a prediction.
But then you won't be able to use this code
because you will have probably
a lot of independent variables and therefore a lot of dimensions.
But you know, care will give you the explanation in 2D.
I'm giving you the explanation of 1D so that now in your mind,
you can perfectly represent in your head
the decision tree regression and how it works.
And now I would like to end this tutorial by an enigma.
In the next section you will see random forests and a random
forest is actually really simple.
It's just a team of several decision trees.
So knowing that this is the result of one tree,
what do you think will get with a team of ten trees
or even 100 trees or 500 trees?
The first question is, do you think we will get this shape
of some stairs here?
And the second question is, do you think we'll get a much more accurate prediction,
like a prediction that is getting very close to the 160 K
that is supposed to be the real salary.
So these are the two questions I will let you think about that.
And I look forward to giving you the solution in the next section.
Until then, enjoy machine learning.