But that's because we have y pred this way in our templates.
And if you don't want this format of widespread, well,
you just need to add a simple argument, which is type here
the type equals and you just need to input class.
Okay let's try.
Let's try to execute this line again.
And here's why.
Let's have a look at Y right now. Y pred.
There you go.
Now why is vector.
As you can see, for each observation of the test set, that is for each user
of the test set we have like before the prediction
0 or 1 for each user zero.
If the user is predicted not to buy the SUV,
and one if the user is predicted to buy the SUV.
According to our decision tree classifier.
Okay, so that's a little thing to change here.
Make sure that you know your Y is your dependent vector of results.
Zero one that we were used to.
Because here, as you can see, we use the same predict function
with the two arguments classifier and new data equals grid set.
So that means that this won't work
because this is supposed to be a vector of prediction result.
Only this time it's for all the pixel points.
You know, the imaginary pixel point users in the grid.
But since the predict function is associated to the classifier,
which is the decision tree classifier,
then if we only keep these two arguments here, then this will make any sense,
because this will return y grid as a matrix of the two probabilities,
and therefore here we will have some problem
because it will be a matrix of a matrix, whereas here it's supposed to be a vector.
So what we only need to do, and we will do it now
so that we don't forget is to add this type parameter.
And we will set it equal to class.
And then it will work perfectly.
So we'll copy this
and add it here as well.
Perfect. And now it's ready.
Now it will plot the graph without any errors.
So I know I gave you a template that is supposed to work
without changing anything to plot the classifications.
I'm sorry.
Sometimes we need to change a little few stuff and that's why we need
to, you know, execute each of the lines one by one to see if it's as it should be.
And besides, yes,
we would have encountered some issues if we you know, computed the confusion
matrix this way with this y as a matrix of probabilities.
But now it will be fine because y is set the correct way.
So we'll execute this and look at the number of incorrect predictions.
All right.
Now let's enter CM here.
And we have six plus 11 equals 17 incorrect predictions.
So now let's see if we were right
to change our code this way so that we can plot the graph.
Let's see if it will work.
I hope it will work because I want to show you
the decision tree prediction regions and prediction boundary.
I really want to show you this.
For those of you who didn't follow the Python tutorial of course.
So let's select this and let's see if we made a good job.
All right looks good so far.
Looks good. No errors.
Let's see what happens.
And we were right.
This works perfectly well.
That's the decision tree classifier.
That's the prediction boundary.
So as you can see there's only horizontal and vertical lines.
That's because as Kirill explains, the decision tree
algorithm is based on some conditions of your independent variables.
By finding, you know, each time intervals that will make conditions
that will classify in some rectangles your observations.
And actually, what's funny is that we clearly have less overfitting
than in Python.
And actually that's why we have more incorrect predictions.
Because in Python we had, you know, red rectangles here, red rectangles here.
There was also red rectangle here
and here.
We didn't actually specified more parameters,
but this amazing output library and that's why it's very popular.
Chose the right parameters, the right default parameters to,
you know, prevent overfitting.
Because here we clearly don't have overfitting.
We had overfitting with Python because of all the red rectangles here
that were desperately trying to catch every user in the right category.
But here it's not the case.
And here it's doing a terrific job at, you know,
classifying correctly most of the red points here,
most of the green points here in the red region.
And as well as this green uses here, who couldn't be well classified for linear
classifiers such as logistic regression or linear kernel SVM.
So here it's doing a pretty good job.
But still we have some incorrect prediction.
That's because that's difficult to classify.
Well if you want to prevent overfitting in your data.
So even if we have 17 incorrect predictions
that's a very good classification we have here okay.
But now let's look at the test set results.
And I'm actually not worried about that because
since we don't have overfitting here, then that means that we're
very likely to have some good results as well on the test set.
Let's check it out.
Test set and execute.
Let's see.
And here is the test set okay.
So as I told you this looks very good.
This is the set on which we have those 17 incorrect predictions.
You can count them if you want. You will find 17.
And it's classifying most of the red users in the red region
and most of the green users in the green regions.
That's quite okay.
By the way, we can see that most of the incorrect predictions are here.
We can see that we have many red points in the green region.
So that's unlucky.
Good.
As I told you, we would rather prevent overfitting than trying to,
you know, minimize to zero the number of incorrect predictions.