Now, here, we will first create or classify an object.
Then we fit to what extent and why train return to that object.
And then we will predict the values of are able using that classifier object.
So those steps are the same as creating a regression tree on their differences in regulation.
We were calling B.S. and Creeley gracer, but for classifier, we have to coalition declassify it.
Again, we are naming this object as our classification tree.
So we are writing CLV, KRI.
This is a very weird name.
You can select your own variable name if you want.
And in the parameters we are passing maximum bet this tree.
Few want to look at all the other parameters that you can pass in this function.
You can head chef PEB and if you remember, we discussed the criteria's such as classification added
Ragini and Cross and Croppy by default.
And this function takes Gini as a criteria.
If you want to test this tree using Crosson, Groppi or any other criteria.
You can just replace Deani with those criteria.
Again, we are taking Max depth as three if you do not provide this boundary condition.
You will get a very large tree which will probably overfit your train data.
But just to easily use relays or KRI, we are first taking maximum depth of three.
Later on we can play with this parameter to get our optimal degree.
We are not providing minimum sample, split and minimum and beliefs.
So let's clear this classifier object.
Next, we will fed this classifier object using our Ekstrand, NY Trin variable.
So our classification tree is ready.
We can predict why train NYC best values using this classification tree and we can corridor predict
my third.
To prayer values.
So we just need to right see a live tree.
There is a classified object.
And we are calling Daudt predict Mentone.
And as an argument, we are providing X strain and expense data.
Let's run this.
Now we have our very good values.
And Wyandotte score tests underscore pride and why underscore Krein underscore Prag.
Let's look at the values of why underscored that Sunday school pride.
You can see we are getting zero one zero one values for our test to.
Now, in regression, we used artist Squirter and MFC to calculate the performance of the model for
classification models.
We can use accuracy, score and confusion metrics.
Accuracy is scored is the percentage of records that we can correctly identify.
Using our model.
So, for example, accuracy of 60 percent means we can correctly identify 60 percent off for viral use
using our model.
First, we will create the confusion matrix for what crane data said.
So if you had to shift tab here, you first have to provide the crew and lose of way.
And then you have to grade the data values of why.
So our crew value is environ, the school train and our predicted values is and why underscore Krein
underscore correct.
So I will run this.
So whenever you call the confusion metrics, you will get this kind of metrics that rose to represent
the actual values.
And the columns represent the predicted values.
And these are categories.
So this is four zero.
This is for one.
And this first column here is for CEDO category.
And the second column is for one category.
So this first story present actual zero and the second row represent actual one.
This first column represent credit trade zero and the second column represent credit trade one.
So we have 172 observations, which were actually zero, and our predicted value is also zero.
This 172 is also known, this grew negative, since actually they are negative or zero, and we are
also predicting ripping them as zero, therefore crude negative here for this 176 that grew value is
one.
Since this is in the second row and the predicted value is zero.
These are known as false negative since we are crediting this as negatives.
But actually they're positive or one for this 14.
The actual value is zero or negative.
But we are treating them as one or positive.
These are also known as false positives, and these are.
Positive.
The actual value is also one.
And we are also predicting it as one.
So from this confusion metrics, you can say that we are predicting this to do right and this 92 right.
And we are not able to predict this one, 26 and 14.
So accuracy scores should be 172 plus 92.
That is 264 divided by the total number of observation.
That is four zero four.
But you can also calculate the accuracy score by just calling accuracy score from Escandon metrics.
Now let's take a look at total confusion metrics for our test dataset.
Again, the roads represent actual values and columns represent projected values.
So these are crew positive.
Dacula Lewis zero.
And we also predicted it as zero for this segment in the actual value is one.
And we also protect 17 observations as well.
You can find the accuracy score by just calling the function accuracy under score score and the role.
So you have to provide grew a loose and uprated values.
So we are providing why underscore tests and why underscore test and that score predict.
You can see the accuracy for our model is around 55 percent.
It is not great, but with some tuning we can improve.
This is skort.
Now, let's applaud this decision tree.
The matter the same, the cold sort of same here.
Just earlier we were using Greg KRI sense.
That was our model here.
We just have to use CNF Cree since our classification model is Silveri.
We are using feature name as extranet or columns, since we can access our column information using
this attribute of our extended frame.
And we are passing this column names as a feature name so that we can see the actual column values in
our tree.
And since we won conditional formatting in our tree, we are calling fairly equated to just run this
for cells to get our tree.
Here, each cell contain four values.
First one is the condition.
So our first split is on budget column and the value at which they spertus taking place is 30000, 694.
Next, we have the genie value for this bucket.
Next, we have the total sample size that is falling under this bucket since this is our top.
We have all our observations in this note, which is equal to four hundred and four.
Then we have the distribution of values.
So there are 186 zeros and two one eight ones in this bucket.
The total should be four hundred and four.
So after our first split of this condition is true.
We are going into this branch.
And if our condition is false, we are going into this branch.
Then further, we are dividing this cell.
On this condition, that is production expense.
And here for this bucket, the genie is zero point one five seven.
The total sample size is today, five.
So today, five observations.
Are satisfying this condition and the rest 369 are falling under this bucket and they are not satisfying
this condition.
Here, the values again represent the distribution of zeros and ones.
There are three zeros and there are 32 ones in this book.
And the color here represent the purity of that bucket.
Blue represent high purity of ones.
So since today, two observations, although 35 observations are ones.
That's why we are getting this dark blue color aura into the present.
High purity of zeroes since here.
Two out of two observation are zero.
That's why we are getting this bucket.
An orange color and white represent no purity.
So as you can see, we have almost equal distributions of zero and one in this bucket.
That's why we are getting our color as right now we can also use our parameters while finding classification
tree to control the growth of our tree.
So earlier in this tree, we were using maximum depth as three.
That's why we are getting three level zero level, first level, second level and third level.
Now we are going to use two parameters.
We first want to provide minimum sample size of our leaf as 20.
So we don't want to get this kind of bucket where we have one or two observations in our leaf bucket.
We want the minimum samples in our leaf to be 20.
And we are going to give him maximum depth of four and sort of three.
Again, we are going to find accuracy scored by predicting our white test will lose from this C11 Kree
to murder.
And we are going to roll this model, Lespwa.
So this is our new CCRI here.
We have provided these two conditions.
And as you can see, a earlier over this branch was further dividing and two subbranches.
But now, since we have provided the condition for minimum leave size, we are not getting this bucket.
So we are pruning this branch and we have provided my son that the fourth.
So this branches are further dividing and two different categories.
Let's look at the accuracy score.
So now the accuracy score for our this model is fifty five point eight percent.
Earlier it was fifty four point nine percent.
So they have improved the accuracy score by one percent just by changing the hyper parameters of this
model.
You can try different values as well here and try to get the maximum accuracy score for this model.