In this particular session, we will discuss about the implementation of decision to use this court
file contains the implementation for random forest also, but that is something which we will be covering
once we have already discussed victory for random forest.
So the first thing what we do is we will import the required libraries.
That is, find us as number as in the Escalon as.
Three, we will import trees from Escala.
We will import numbers, and B, this is not required.
It's again then we have Escalon metric.
Eskil on that metric contains a lot of metrics which we can use for analyzing and for evaluating our
models.
So I would suggest you to go to Eskil on Dot Matrix and check the documentation from Escalon and see
what metric is used for what purpose, I will do a separate video for different types of matrix, so
don't worry about that.
So for now, we will import a U.S. score and we will be making in mudflat clip in light, which means
that we want to.
Pretty much a plot in this before.
So once we run this, we will import the CIA tree so the CIA train data will be coming from this particular
fight.
So we will import the five.
Census info, and we will read this file using.
They did not read CSFI.
Now to explain the fine can be placed in any folder, but currently this file is placed in the same
folder as this Jupiter notebook, which is the reason why I have simply given the file name in case
the file was placed in any other directory or folder.
Then I would have said slash data.
Slash some folder name.
And so on for the topic, and this roistering reader will actually help in understanding the characters,
these data in the raw form so that these values are not rendered some other character.
So we will import this and we will import data from us three.
Now, in case you have a test data, then you can combine the best data as earlier in the earlier model,
as we have shown.
So what you can simply do is you can combine the data in the same data frame and from the data frame
itself, you can give it a name.
So we'll see then how we can do that.
So far now we have this data c.i.t..
And we have got hit, so we are checking the details which are present in this particular data frame,
so we have age, which is numeric in nature.
Then we have the will class.
Class contains values like Steve Goman, self-employed, so what is the class?
It belongs to if someone is doing a government job or a private job or if he's self-employed.
So all these details are present in the middle class, then we have final vote.
We don't really know what this value is the big thing for, but we have this numeric value here.
Next is education.
Now, this education value has bachelor's bachelors, high school graduate, 11 bachelors.
So these are different values which are present in the education.
And in decide this, we have another column that is education.
No.
This education number, again, has values 13, 13, nine, seven, 30, so.
It seems to be that these are numeric codes for this one, but we will evaluate that little.
Next, we have marital status, there are multiple statuses like never married marriage, civic spouse,
then divorced, then we have occupations.
These occupations are.
And local executive managerial handlers, cleaners, profession speciality, then we have a relationship
that is someone is not in the family or someone has a husband and if someone has a wife.
So these are different relationship status of the people.
Next, we have the breeze, which is either someone is white, black, Asian, whatever it is, then
we have sex that is male, female, these values.
Next, we have values like capital gain, capital loss, then hours per week, how many hours per week
a person walks, then the native country for that person.
And finally, we have value, which we want to predict.
That is if the person is earning less than equal or greater than 50.
So from this data set, you can see that why is the value which we want to predict?
And the rest of the columns are actually the X values, which we want to use as the features or attributes
or input values or independent values, you can see.
And why is the label or target or you can also say dependent variable.
So these are different films which we use for the white.
Now we can look at the head value for the train dataset.
So this is the train data center, which is, again, just to see now what we can do is.
Here I am showing the values which have been created after the transformation.
Now you can see the values have been converted into numeric values, which is the target here.
So our main target is to convert all the data into all the data instead of it being the.
Categorically or any data.
So all of this data has to be converted into numeric data right now, what all can we do to convert
this into unlimited data?
Because the algorithm cannot really understand these words.
The algorithm does not know what BATCHELLER means and what private means, what has been means, what
it means.
So all these things are nothing for the algorithm.
It will only understand what thirty nine zettl one these numbers are.
So it will only understand the numbers.
So our main focus here is to convert all this data into numeric form.
So now how will we do that?
So let us have a look at each and every column, so the first column which we have is each now this
column is already in a numeric form.
Next, we have a class.
So the world class is in a categorical form.
So we will have to convert these categories into numbers.
And how do we do that?
We can avoid that by using one word, encoding or dumbing creation.
Next, we have finally this again, looks like a numeric variable, but in case it is not, we will
convert it into a numeric by error course.
Next, we have education.
Now, again, it looks like a categorical variable.
So we will see what all categories are present here and here.
We have education number.
So we will try to compare the relationship between education and education number and find out if these
are related or not.
Next, we have marital status, so this, again, looks like a good column, so we will have to convert
this into one two, including next we have occupation, which again would have to be converted into
one.
The same applies to columns like relationship, race, sex, then the column Native Country.
So all of these columns and column have to be converted into a dummy form.
So now let us do one thing, so let us apply Findus profiling to it.
So I have just applied Fondas profiling by importing profiling report from Findus profiling, and I
have generated the report using fear and putting Citrine in it.
So this is the profile report which I have obtained from this.
So here you can see that the number of variables on 15 numeric variables are six.
Categorical variables are nine.
Out of this, the data set has twenty four duplicate laws and capital gain has ninety one percent zeros
on capital loss, has ninety five percent zeros.
Next, you can see the type of values which are present in each.
Here is the detail of the capital gain.
Here is the videos of the capital loss for education.
You can see that the top four categories contain most of the data, while these categories contain less
than five percent of the data.
So we can decide if we should keep the top five categories on the order of four categories only and
we can remove the other categories.
So for this, we can actually run different variants, one variant with the top categories and another
variant with all the categories present and lifting, which we will be learning, is getting the feature
importance.
So we were able to get future importance from the logistic regression also so we can use that and obtain
the of important features from that as well.
So next, what we have is these days.
So, again, we have education, No.
Here we have the final eight hours per week.
You can see there are four different values.
So here are different values, which are married, spouse, never married, divorced, then separated,
then widowed, battered spouse absent, married if spouse.
So out of all of these, we can clearly select only the top three categories and keep other categories
in others.
Next, we have these values where the major people are actually from United States.
And next, there are a lot of countries for other people.
So we can keep the first category that is United States and make under the category as non United States.
Next, we have occupation, so for occupation, you can see that we have one, two, three, four,
five, six, seven, eight, eight categories which are having more than five percent of the data so
we can decide upon if we want to keep the rest of the categories or if we can put them into other categories
or should we keep those categories or not.
Then we have this, so for this again, we have eighty five percent white, ninety nine point six percent
black and three point two percent Asian.
So what we can do is we can simply have three categories, one being white, another being black, and
the rest of the values could be put into other categories.
Then we have a relationship, so in relationship, again, as these four seem to be the major categories,
we can create these four major categories and rest we can put in the other categories.
Or as there is only one category which would be left, we can also keep all of these.
So that is all we can mean the means for this.
Then because sex has only two values, so we can easily create one variable for that.
Next, we have world class, so for this world class, again, we have.
Around six prominent categories, and apart from that, all could be put into others.
And then here we can see that for the very values, less than Feki is almost twenty four thousand and
the greater than fifty seven thousand values.
So here you can see that the ratio is quite different.
So that is almost seventy six, forcing all values into one class and twenty four percent values in
the other class.
So when we have such kind of data, the one class has more values on, the other has less number of
values.
This means that the classes are unbalanced.
So when they have such unbalanced classes, then what can happen is that because there is more number
of values having less than four Feki, then the training might get biased towards less than 50.
And for all the values, it might start of predicting that the value is actually less than 50.
So what we need to do here is instead of keeping these values like this, we will be using a great idea
that this glass beads the glass, which will actually help us in a way that they will allow us to give
equal weight age for this particular class.
So that it is not getting overpowered by the other guys.
It will give equal weight to the values of this class also in comparison to this class.
Next is the correlation values, so as there are no specific columns which are very dark in Cologne,
neither in the right side nor in blue side, so we can easily see that there is no specific correlation.
And the same thing has been depicted in the above.
There was no specific correlation depicted here and there were no columns which were rejected.
So we are going to go with these columns and these details.
So the next thing which we will be doing is we will be comparing the education problem with the education,
no problem.
So here you can see that the values for education and education number are actually correlated.
That is that first and fourth actually refers to the education level one, level two five to six level
is basically education.
Number three, seven to eight is education number four.
Ninth is education.
Number five, the intent is education.
Number six 11 is education.
Number seven, 12 is education, number eight and so on.
So what we can do is we can simply remove the column education and keep only education number in our
dataset.
So we will simply Skytrain ball drop and remove the education column from this particular dataset.
Next, we will get the count of the value.
So we already know that the count of the values is actually unbalanced in nature.
So we will have to take that into consideration by training our model.
But for now, what we will be doing is we will convert the CIA train by column into a dummy column.
So for that we will simply use ITIN VI is equal to greater than 50.
So whenever the value is greater than 50, it will put that as one.
And whenever the condition is not satisfied, if that does zero.
Because this is a condition.
This condition will be evaluated, and when this condition is evaluated, it will give one false.
So when this condition is true, it will give.
True and true, Wengen voted to impeach and gives one and false is converted to invasion, it will give
them.
Next, we are getting all the columns, which I've got the vertical columns by using Katrien to select
the types.
So this will give us all the data, such as object data.
And then we are selecting the columns out perfect.
So we get all the categorical columns.
So these are the different categories of columns which are present in this particular dataset.
Next, we will we have created this particular law, which will actually allow us to create a cutoff
for the column creation so that we can actually obtain only some amount of categorical columns, only
some categories converted into the dummy columns and not all of them.
So it is only new thing on top of the different categorical columns and.
Getting the values of columns and then it is running on the citrine, I'm getting the different value
counts and these value columns, I get best frequency's.
Then from the frequency data, it is checking if the index of the it is getting the indexes of the frequency
is the frequency value is greater than five hundred and it is checking the category in.
And so it is just creating a name.
That is the column plus the category name.
And it is creating the column name using this, so what it does is it just creates the got the got a
good column out of the columns, which we have.
So we get we have one plus column marcosi, this occupation, relationship, race, sex and native country.
So for all of these columns, these have been converted into a categorical two or three to one, including
two Dubnyk lists.
Next, we are just checking the shape of the data now, so now we have thirty nine columns in hand.
So the next task, after converting all the columns from can go to the column to the columns or whatnot,
including yours, to check if there is any value or not.
So we will check the data by using DOT is not a dot dorsum, so we get all the column values.
So here we can see that all the columns are actually Ziegel.
And here you can see that these are the columns which have been created.
So the relationship value hundred husband relationship, not in a family relationship or child relationship.
Unmetered Relationship five, this white is black.
So these are different columns which has been created using the dummy creation.
Now we are simply getting the data.
Into extreme, so extreme contains all the problems from CIA except for the vehicle, so that is why
we drop the big column from the axis equal to one.
We can ride this lake.
Axis equal to one or two, it'll be just the same thing.
Next, we have vitrine.
So we are putting the V column into right now, there are different type of barometers for Decision
B, which we have already discussed about.
So we will be training for these different hyper barometers and these on these different hypovolemic
as we will be getting the values of the hyper barometers which give us the best model.
So we are implementing the randomized so TV, so we have already discussed about the grid search now
in a grid search c.v, what happens is that the grid search will give us the combinations.
It will run all the combinations which are pressing everything.
And then from all the combinations, it will select the best one.
It will run all the combinations from the bottom.
So if I'm giving these barometers, it will run all the combinations out of it and then give me the
result, like what random solar TV does is that because we don't want to put in so much time into running
the code.
So what we will do is we instead of using the digital TV, we will use the random thoughts.
So what it will do is let's say we have one hundred five orders which are being created using grid TV.
So instead of running those 100 models, it will randomly select 10 or 20 models, whatever number we
define and run those.
So in this way, we will actually run a random selection from those markets.
Now, the benefit is that it will save us a lot of.
But there is another drawback that is we will be losing on a particular one.
So there might be some model which would have been better than the one which we will receive by running
the random lines.
So see why we would have used the TV, but because we want to see if that is why we are using randomizer
TV.
This is good when you are running for sartin proof of concept or you want to get a model very quickly,
then you can use my TV.
But otherwise if you want to do a quick thing but actually run extensively and get the best model.
So in that case you would run the grid.
So it would be and there are different methods which will actually ease the running of TV, but that
is something which we will learn in something later.
Maybe in another topic because of the I don't want to make it really fast so that you get confused.
So for now, we will have a look at this randomizer TV.
So if you want to or don't really list any time, I just want to have a one week run.
Then you can use a screen split in case you have a moderate amount of time.
You can use randomized.
So TV.
But if you want to run the phone extensively and try all the possible combinations, in that case you
will use the grid.
So it's.
So let us go for the.
So here.
We have different parameters, so these are different barometers, which we have that this class meet
criterion, maximum depth minimum, some believe minimum sample split.
So these are different criteria, which we have.
So we will be trying all the combinations.
Next is another thing is like instead of having just one minimum belief, you could have had a larger
size of criteria's.
So this is another criteria which would work better.
So it is a completely dependent on you.
How many samples, how many parameters you want to put in?
Usually what I would do is I will try of three values or four or five values, and out of those values
I will select the best ones.
So how would I do it?
Minimum's, I believe values.
So I'll try five then.
15, 20 and 25 now out of these values, let us see, I get no value for theme.
So in that case, I will eliminate five and twenty five and then I will add another value.
Here I will add value 12.
And Values 17 here, and I will eliminate the five.
I'm twenty five.
This way, I will actually get to know and I will then also.
Because if it was actually then, then it would have chosen then.
So now I have these three values now based on which in which direction this election goes.
So if the best model comes out to be 15, then we are good in is the best model comes out.
We do it.
Then what we can do is then we can eliminate 70.
And we can run something which is between 12 and 15, 13 and 14.
Then we can run something like this.
This way, we will be able to narrow down the selections, which we are.
So this is how you can run this.
So here what we are getting is we will be running through of the Glaspie to criterions.
For.
Maximum bet values.
For three minimum, some beliefs and three minimum sample split, so the total number of runs which
we will be having a number of models, which we will be having, will be to cross the cross for cross
three.
So in total, I have 144 murders and I'm a third thing is that this is a decision three and I will be
running then cross-validation.
So it will be in Dotan.
So.
They will be in total one thousand four hundred and forty more dollars, which will be created if I
was running a grid.
So a TV.
But the good thing is I'm using randomise so TV, so now what will happen is first thing first I will
import the Escalon tree that this decision to declassify.
From this, I will create an object of decision to be classified as sealife.
And in my randomise.
So it's KVI, I will give the details that I want to run this cliff model that are in cross-validation,
which I want to have.
These are the parameters which I want to run this clip for, and this is the scoring method which I
want to use a bathroom that I will give.
And I do this and either means how many more those do I want to select from these 144 words?
So if I say I want to select 10 models out of these 144 models, then it will select.
Then more days and it will run then cross-validation from this, so it will give.
Into then that is one hundred more, those will be built instead of one thousand four hundred and forty.
So now you can understand how it is of easing the run, so instead of having such a huge run, then
we will have a lesson one day.
That is, we will have to run only a hundred more days instead of one thousand four hundred more.
So running the randomizer, TV has its own pros and cons.
So that is something that you can evaluate based on what kind of work you are doing and what exactly
you want, what you promised.
So the next thing which we will be doing is we have created the object of randomizer TV.
So this is the object of random TV and we will find the.
Extranet, vitrine, when we find the extreme and white rain, it will take some time to run because
we have so many parameters ReGive running and there are around hundred more of those which are being
created internally.
So it will take some time.
It will learn from this extreme NYG and after learning from this data.
It will give the best estimate using random search talk, best estimate.
Now this is the best model which we have received from this and this best model is having the class
with as balanced.
The criteria is Guiney.
The maximum depth is five.
The maximum number of features is none.
The maximum Leaford is none.
So these are different parameters which it has chosen from these group of barometers, which we have.
Now, you can also go through the documentation of Decision three and see what all other hippopotami
does.
You can select and view this model for these are all called hyper barometers, which we are tuning.
And this is exactly what you need to do.
You need to have patience and give it the time to clean.
And once you have the model in hand, you can make the predictions.
So this is everything here is actually a task of patience.
If you have enough patience and you know which type of barometer to choose and how to deal with these
hyper barometers, how will check which value you need to use is exactly what you need to know here.
Now, let's see if I would have had values, let us see five and then and 15 and somehow I would have
got values 15, that means that the value is marginal value.
Now, the value could have been less than 15 dollars, one greater than 15.
So in that case, in the next run, in the next training, what I will do is I will give some value.
See twenty five here and let's say 20 or so, so that I will get to know if actually the value was 15
or it was something less than 15 or greater than 15, because I don't want to lose on something just
because I didn't run the random search again or grid search again.
So once you run this is randomized, so you will get some parameters, then you can modify the parameters
and run these models individually or by changing these hypovolemic and running a grid search on top
of these so that you can get a better result and improve your fine yield.
More value using that.
And the Mysore TV will also help you to get the benchmark for your.
So you can decide, OK, for now, my model is performing with seventy five percent accuracy.
So now after the morning the hippopotami goes, how much is it improving?
Is it actually improving or not?
And what is the accuracy value for this in comparison to other models, let's say logistic regression
or random sort random forest or examples which we will be learning in coming times.
So you can be you will be able to compare these mortgage.
Right.
So this is what we will be doing, this is how we will be training on borders and working with this.
So once we get the best estimate, then you can use this particular function to generate a report from
this.
So I have generated one report and you can see the score, which I have, of being this zero point eight
nine one, which is the best score.
And the next I have zero point eight nine zero zero point eight eight nine.
So the best one is zero point eight nine one.
And these are the barometer values.
Next, what I will be doing is still I have the best estimate, but I have not received it anywhere
on my model is still not prepared.
So what I will be doing is I will take the random surge, Lord, best estimate.
This is the model which has the best performance.
I will take this message to me and put it in the big.
This is my new video which will hold the new model, the best model out of all the models which random
searches bring.
After I get this dream, I will again fit my model on the screen and by train using the new parameters,
the and that is these best barometers, these best barometers, again, I will fit the model and then
the model, which I get that does this deeply will be the model which has the best performance.
Now, I can actually visualize a decision tree, so for visualizing a decision tree, I can simply say
open my tree dot w.
Coma W, which means that I want to write this particular fight.
And this is the trial has been created, then this is the new fire which has been created and I'm just
exporting the model to.
This particular fire took to this particular deadly fire, to this dog fight.
So after that, I will simply close the file and I can visualize this particular tree using Web graph
with dot com.
In this, you can actually see how the decision tree looks like.
So let us visualize that.
So this is the fight which has been generated, which has all the details of my decision tree, so you
can see that it has details like different rules which are used for this particular decision, tree
creation.
So it has all the rules associated.
So I'll just show you what exactly will do.
We just copy this entire text into this file, which we have.
So I just copied this and I just click generate graph and it will generate a graph for me.
And below it, you can see the graph which has been generated, so it is a very huge graph which has
been generated.
So this is what it looks like.
So you can see it is a very huge graph, so this is the roof node, which is marital status that is
married to a spouse, it is less than equal to zero point five.
Guiney value is zero point five.
The samples are one hundred percent.
These are the values.
These are the classes.
So very now this is the condition where the spouse is true and accordingly, the capital gain.
This is the next rule.
This is the value of it.
So here you can see the value was zero point five.
Here the value has reduced to zero point two nine for the number of samples are now fifty four percent.
And you can see that the values are zero point eight one nine and zero point one.
And one has predicted the glass to be zero, so, so on.
It has just generated different class values and thus it keeps on reducing the value accordingly.
So you can generate your own decision using this.
And analyze the scene.
Thank you.