So in this video, we are going to learn how to create a classification decision tree in our.
The template that we created for Regression Decision Tree, the same template can be used for classification.
Only few modifications need to be done.
I'll point out, wherever you need to do those modifications, you can use the same template that you
created for regression decision tree.
So copy paste that code.
The first part is importing the dataset.
Just ensure that you have the correct name.
This file is also attached to the resources.
Download that file and import that feed.
So I run discom on.
Now, if you want to view this data, we on this beauty of.
You can see that it is almost similar to that previous data.
Only thing is that collection now is a independent variable, that is.
This will also be a part of the predictive variables.
Start big Oscar, this variable is the deepening we will know the value of this variable we are trying
to predict.
I mean, if there are any missing values, we need to do missing value imputation, so that part was
captured in the data preprocessing.
I learned these two commands to impute dismissing values.
This is similar to what we did earlier.
Next step is to split the data and to test and train for that.
We will use the package.
Seattle's.
So if that is in store.
If that is already installed, would you just go and find it, see it old is already installed.
You do not need to run this.
You can just run this command, which is Lively's here, dude, to make it active.
So now it is actor
now in the same way.
We will split this data into test entry, so let's select these three, these four lines and run them
together.
Why it control ended.
I have changed the name of train and said to two trains and see so that.
They do not override the previous test and train it.
So now we have test C and trained C for declassification model.
Now we are going to install the packages required for creating a.
For creating the ABC entry, you know that we used our part and our part blog.
So just go ahead and take whether they are installing active, if they're not installed on these two
commands, if they are not active, then these two libatique a month.
For me, both of them are distorted and active.
So I'm not going to run these full length.
Next is billing the classification tree.
Earlier here, we had read three variable.
Now we are putting the information in two last three rebill.
The function that we are going to use the same it is our part only.
The only change that you need to do is to mentioned this method.
When you are doing classification, you need to use a method is equal to plus.
Just all of those things I seem to control, but I'm mean, that is again, Max, depth is equal to
three.
That is the maximum depth of our tree is going to be three levels.
I'll run this and you can see that the upper class street variable is created, which has data of the
classification tree.
Next, if you want to plot that decision, tree we use are our part, not blah function.
Here you'll just jeans that rig three very well do.
Three, since we want to applaud this classification tree.
So if I run this.
It is a classification tree.
So let us take a look at this classification tree initially.
Hundred percent of my population had an average of zero point five tree, meaning that there is 53 percent
probability of getting a Star Trek Oscar for the movie.
Now, the first split is Baz's budget variable.
If the budget variable is less than 30000, which is for this region, for these eight point four percent
of the movies, that is 93 percent chance of getting an Oscar for the movies which have higher budget.
We make and I just played Bishes collection.
If collection is more than 63000, there is seventy eight point six percent probability of getting an
Oscar.
Whereas if collection is less than 63000, there is 44 percent probability of getting an Oscar for that.
It is split into two parts.
Versity producer rating.
So using this decision tree, you can predict whether a movie is going to get a star, take Oscar or
not.
Now, when we are trying to predict a value using this classification decision tree, we use predict
function.
This is what we used earlier.
Also, the difference between this predict function is an X parameter type is not going to be equal
to vector.
The type is going to be equal to plus.
So for regression, we use a musical director for classification we use type is equal to loss.
If I run this.
In my test, see, I'll get another variable.
Which has deep predictions that whether a movie is going to get an Oscar or not.
Bases this decision tree.
And lastly, if you want to compare the performance of the classification to see Indri, one of the
method could be to plot actual values versus the predicted values.
So if I plot this table, if I run this command, you can see this is what I'm getting.
Hit on the nose.
We have actual values.
That is for the Fosterville.
The movie did not get any Oscar out of these 47 cases where the movie did not get any Oscar read correctly
predicted for 40 cases.
So actually, 47 movies did not get the Oscar.
And we were right in predicting 40 of those cases.
In the second row, we have sixty five observations.
That is sixty five movies actually got the Oscar.
Out of those 65 movies, we correctly predicted four, only 23.
So when the movie's actually winning the Oscar, we have a very bad prediction, accuracy.
Whereas when the movie's not actually winning the Oscar, we have a very good prediction, accuracy.
If you want to check the overall accuracy that is overall, we had 63 correct guesses and 49 incorrect
guesses.
So 63.
Out of one one, two is a prediction accuracy.
If I had this coal mine, you can see that I'm predicting correctly four fifty six point two five percent
getas.
So then I had the population when I had the total population.
If I was guessing that each movie will get the Oscar.
My prediction accuracy was going to be fifty three point six percent.
But with this model, my accuracy is nearly 56 percent.
There is a very slight improvement in predicting using this decision.
Tree in the coming videos will learn how to improve the accuracy of vision trees using advanced techniques.