Hello, everyone.
In this video, we will learn how to build classification Tree and Biton will follow exactly the same
steps that we followed while creating regression tree.
So let's start.
First, we will import all the important libraries.
I have copied this code from my regression tree.
You can also copy that.
Good.
Here I will import my movie classification CSP.
We have already discussed the variables of this data.
So let's just import and to view the top five rows of this data frame.
We will eun's head.
This other top five rows.
You can see we have variable name on the top of this table.
Our dependent variable is Star Trek.
Oscar.
And since this is a classification problem, our dependent variable is taking zero and one will lose.
Now to get details about the type of each variable type and code of values in each variable we can use
in full.
You can see the 506 and Creese.
There are 506 observations and all over variable names are listed on the left hand side of this table.
We have combed off Martinel values.
And you can see time taken biddable, have some and use in their.
Now we need to do missing value imputation for our time taken variable.
First, let's calculate the mean of this column.
So the mean of this time taken variable is 157.
And we will impute all the missing values with this mean value.
We will lose Phyll and then my third and then will provide value, which is equal to mean of this variable.
And since we want permanent changes in our data frame.
We will give in place parameter of value of crew.
Let's run this and let's try to run in four again.
Now you can see that we have imputed the missing values and now the county's 506.
Again, there are two string variables, categorical variables through be underscore available and John,
that you can identify the vertical variable sort of string variable using this type column, the type
of string variables as object.
Now, as we have already discussed, to convert our categorical variables into a dummy variable, we
can use get demis method of panda.
Here we have to first mention the data.
So the ties, dear.
Then we have to mention the column names that contain our categorical variable.
So our very real name is truly underscore Welliver and Johna.
And since we are providing two variable names, we have to put it in a list.
I have put this to a loose and I squared record squared record represent list.
Then, since we won't end minus one, get degrees.
We have to give this drop underscored first parameter of value of crew.
So let's run this and let's again take a sample of phosphide values of our data frame.
You can see now we have dummy variables for 3-D underscore available.
And John, critically.
Now we need to debate over data frame and to X and Y X's sense for our independent variable and Y sense
for our dependent variable.
So we need to select all our variables as independent variable.
Except a.
Oscar variable.
And this is a very dependent variable.
We can do that by using LOKKE method.
So we can write B.F. Dog Block.
And then since we want all the rows, we will put just Skogland symbol.
And then after POMA, we need to mention the columns.
And here we are mentioning that all the columns except Spartech Oscar column.
So always remember for Lokke.
You have to provide two parameters.
One four rows and one four columns.
And these two should be separated by a comma in between.
And if you want all the rows, just put a colon.
And if you want all the columns, just put a colon after this comma.
Let's run this.
Let's look at the first five rows of forward equity with.
You can see we have all the variables except star tech.
Oscar Collum.
Now let's review the number of columns and rows in our extra Dufrene.
So overall, there are 506 rows and then take almost an hour extra frame.
Now, let's create our dependent variable, which is why variable here we need on the Spartech or Scuttle
column from our data frame so we can simply add IDF and in the squared record, we can mention the column
name.
Let's look at the first five values.
You can see we have the first five values and values are in the form of zero and one.
Let's take a ship again.
See, there are total 506 observations.
No, next thing we have to do is to delay the hour X and Y variables and to test synchrony split.
Remember, we did the same process for over regression tree also.
We will lose their trend, split from a skill and dot model selection.
And the output of this function is in the form of forward series or data frame which we are saving and
exten expressed by train and by test.
Again, we are selecting that train sample size of 80 percent.
And test size of 20 percent.
That's why we have provided zero point to in our test size variable.
And here in random demonstrated you can mention any number.
But in this skorts we are always going to use zero two.
The same is split for every model radiation.
Let's run this.
Let's look at the screen dataset.
You can see this is overtrained or does it start?
Take Laskaris not here on let's take us shape to know the number of observations in this dataset.
So 80 percent of 506 is four 04.
That's why we have four hundred and four observations in our extreme data and in our extended day we
should have one hundred and two observations.
So we have divided our data, which had 506 observation, and to extend the next steps containing four
hundred and four and hundred and two observation respectively.