So let's try.
Let's now reselect this section to create a new regressor.
So our part is already imported so I don't need to select that again.
And let's create this new regressor.
Okay. Done.
Perfect.
New regressor created all properly. Okay.
And now let's perhaps first visualize the results
to see if our model is now correct before getting to the final verdict.
Because, you know, we need to validate the model. Now.
So I'm selecting this section and let's see what we get.
Let's cross our fingers.
Here we go.
I'm going to zoom on the plot.
And now the first word I have to say
here is trap or red flag.
Right now we're just in front of a new trap.
The model is improved.
Definitely.
We can definitely see that we have more than one splits here.
For example, here, that's a split.
That's another split here and here.
So okay, we solved the problem of the number of splits.
But according to what Kirill explained in the intuition tutorial,
do you think that the real shape of a decision tree regression model.
Well, because you know, what Kirill explains is the algorithm of decision tree
regression is that by considering the entropy and the information gain,
it's splitting the independent variables into several intervals.
So in the intuition tutorial you had two independent variables.
So the different intervals formed some rectangles in which
you took the average of the dependent variable values.
But here, since we are in one dimension, that means that the algorithm
will only take intervals here of the independent variable.
For example, that should be one interval.
And here it looks like it's the second one.
And here it's the third one.
And here a fourth one.
Okay.
So basically it looks like we have four conditions
and four intervals that are making the splits.
But as you understood
in the intuition tutorial it's taking the average in each interval.
So if it's taking the average how do you want to have this
straight line here that is not horizontal.
Because you know what the decision tree
regression is doing is that in each interval it's calculating
the average of the dependent variable salaries.
And therefore for all the levels contained in this interval,
the value of the prediction should be a constant equal
to this average of the dependent variable in this interval.
And here, as we can see, it's not a constant.
You know the prediction here is not the same as the prediction here.
So either it's considering an infinity of intervals
with different constants in each of those infinite intervals.
Or either we have a problem here.
Of course it's not the first option.
Of course, the decision tree regression is not considering
an infinity of intervals between this level and this level.
So it's definitely the second option.
So now do you see where the problem comes from.
Well the answer is in our regression template.
Because what we observe here is only due to the resolution
we picked to plot these decision tree regression results,
because we are actually plotting the predictions
for each of the ten levels incremented by one.
That means that here, you know, it's only plotting
the predictions of the ten salaries corresponding to the ten levels,
and then it's joining the predictions by a straight line here,
because it had no predictions to plot in this interval
here of the independent variable level.
And the fact that it's a problem for this new non-linear regression model,
the decision tree model is due to a very specific reason
for the previous non-linear regression models.
We could use the code that generated this plot
because the models were actually continuous.
So for example in the polynomial regression model
well between these prediction and these prediction,
well it was actually almost a straight line here.
However, right now we are facing a new kind of regression model.
Remember the first kind of regression model
we studied was the linear regression model.
Then the second kind of regression model we saw was the nonlinear regression model.
And now we're facing a new kind of regression model.
It's the nonlinear and non continuous regression model.
Indeed all the previous regression models that we saw,
whether they were linear or not linear they were all continuous.
But here the decision tree regression model is not continuous.
And this is the first non
continuous machine learning model we are seeing together.
And so do you know
what is the best way to visualize a non continuous regression model.
Well as I was telling you the answer
the solution for this is in our regression template.
So let's have a look.
And actually we need to take the code section
that visualize the regression model results in higher resolution.
So let's take this and let's actually go back to our decision
tree regression file and replace this code here.
Because this is totally not appropriate
for our decision tree regression model because it's a non continuous model.
And so we need to replace this code by the same but for the high resolution.