Okay, my friends.
So let's smash together this last final step.
Visualizing the decision tree regression results in high resolution.
All right,
so we're going to do
kind of the same exercise as what we did previously with the SVR.
You know that funny exercise where we start from the polynomial regression code
for the visualization of the results, meaning this one.
So we're going to start from this code.
And then the exercise for you will be to make the right change
or changes in order to make this work for the decision tree regression model.
If we did this successfully for the SVR model, well,
it will be a piece of cake to do it for the decision tree
regression model, because indeed no feature scaling was needed.
And therefore
we won't have to play with the transform method or the inverse transform method.
And therefore you will just smash this.
Okay. So let's do this.
That's the exercise.
So let's take this whole code here.
You know which plots indeed the regression curve in high resolution.
But for the polynomial regression model
let's paste that right here in the new code cell.
And now well there you go.
Please press pause on the video and make the right change or right changes
in order to make it work.
For decision tree regression model okay.
Good.
So now I'm going to implement the solution with you.
And let's start with the obvious change.
Let's replace polynomial here by well decision tree okay.
And then what was the change or changes you had to make.
Well as I told you here it's super easy.
You just have to change two things.
And actually only one row which is row number four.
Right.
Because this row number three is totally fine because here x
and y are on the right scale, you know, because no feature scaling was applied.
That's fine.
And here well, the obvious change that we have to make is of course to first
replace this regressor by the right name of the regressor, which is regressor.
All right.
Good regressor.
And then here, you know, remember this poorly rag transformation object
was used to transform the matrix of single feature into this matrix
of the same feature at different powers, part two, three and four.
And this time here.
We absolutely don't need that because we're not doing polynomial regression.
So I'm removing this and then also a parenthesis here.
And now guess what.
Well that's done right.
That's the simple visualization code.
When you know you don't have to apply feature scaling,
and you don't have to transform your matrix of features
into powered features as in polynomial regression.
So that was as simple as that.
I told you. Right.
But now that was a good news.
And now I have some bad news.
You're going to see that
the results are not going to be pretty, because indeed, let's do this now.
Let's execute this cell.
There you go playing.
And here are the decision
tree regression results I really want to say this again.
The decision tree regression model is really not the best adapted
to two dimensional data sets.
You know, with only one feature in one dependent variable.
But once again, I'd like to remind that the implementation we have here
can be very easily adapted to any other data sets.
And I will show you what to do at the end of this tutorial.
You know what to change in this code,
but I still wanted to show you the decision tree regression results in 2D.
And so why isn't this pretty?
Because you know what this decision tree regression model simply
did was to take the real results.
You know, the real salary for each position level,
and then for all the position levels from position level minus 0.5
and the position level plus 0.5, well, it predicted
the salary to be the same as the position level in the middle.
All right.
So that's what it simply did.
And that's you know, understandable and intuitive.
You know to understand because you know how decision trees work.
They work by splitting the data through successive nodes.
And so at the end, you know,
you get different ranges of the features where the prediction is the same.
And so here all the predicted salaries
in this range of position levels are just the same.
And that's why we have this stair looking like curve up to the last position level.
And of course here this is not continuous.
This is actually a vertical bar.
So the regression curve here is not continuous.
We jump from position level to the next one every step of one okay.
So not pretty at all.
Not relevant at all in 2D.
But I still recommend to try the decision tree regression model for higher
dimensional data sets because indeed it can actually have great performance.
All right. Great. So congratulations.
Now you added this new machine learning model in your toolkit.
And now we will tackle together the final regression model of this part two.
And until then enjoy machine learning.