All so in the previous session, what we have done, we have basically extract some desired features
from our data and then all of our sessions in all our previous sessions, we have analyzed our data
as well as we have understand our data.
And that's a time to approach for your machine learning.
So in this session, what we are going to do, we have this amazing assignment in which we have to apply
feature encoding techniques on data.
So very first, let's understand why there is a need of feature encoding techniques and what are different,
different type of encoding techniques.
So, yeah, so you will figure out here you have direct, here you have direct and all these kinds of
string like things like machine learning now understand an extension data.
So it means we have to convert this data and do some numerical format using some feature encoding techniques.
That's why feature encoding techniques come into existence.
So in this session, what we are going to do, we are basically going to use our technique, a very
popular technique known as mean encoding technique.
So let's understand what exactly the mean encoding technique.
So if you will figure out in this market segment, let's say in this market segment, here you have
so let me show you a thing.
Data underscore, get of market segment, just press tab.
And if on this I'm going to call my unique and if I'm just going to execute it, you will see it has
that much unique number of categories.
So what meaning coding will do mean encoding will basically see whatever will be the mean with respect
to this direct column.
Or you can say whatever the mean of the direct with respect to this cancellation column, because cancellation
is exactly my independent feature that we have to predict.
So what are what will be the nien of this act with respect to this cancellation?
I'm basically going to replace Garecht with that mean.
That's what my mean encoding will do.
So if you're not that much comfort, let me show you a code so that you all can understand.
So here what we have to do very first, let's say we have to extract all those columns on which we have
to perform these techniques.
So if on this data underscore that if I'm going to call my columns or they are just execute and these
are exactly all the columns, let's say here, if I'm going to say in these columns, I just don't need
this cancellation because I don't have to encode this feature because this is my defining feature and
this is that what we have to predict.
So it means I'm going to cost zero to it.
And here I'm going to say zero to tailgated.
And if I'm going to execute it, you will see you don't have this cancellation column.
Now I'm going to store it somewhere else, let's say columns, and I'm just going to print it as columns
just execute.
And you will figure out these are my all those columns that we have to include.
So I'm going to say for column in this cost list, it means I have to think it means I have to fetch
each and every column.
Then I'm going to see data on the scorecard.
And this time I have to group my data on the basis of each and every column for this.
I'm just going to say, let me show you a very, very basic example over here.
Let's say I'm going to say data on a scorecard and let's say I'm just going to access my hotel.
So if I'm going to exit this hotel, you will see all the stats.
And now what I have to do if I'm with the group on the basis of this hotel.
So for this, I'm going to say I have to group on the basis of all this hotel.
Once I have this group, by then I'm going to access my calculation, which is exactly this one.
So I have to just access this.
So I'm going to say this is exactly my calculation.
And on this, if I am going to call me Nordea, so let me just call me.
And if I'm going to execute, you will see with respect to City Hall Hotel, you have that much me with
respect to this resort hotel, you have that much mean.
It means what you can do wherever you have a city hotel, just replace it with zero one, two seven.
And internally, my machine learning model will able to understand what exactly the meaning of the zero
point two seven, because machine learning now understand what a city hotel is.
Just understand my Intisar and data.
So we have to tell the machine learning model.
Yeah, this is exactly my city hotel.
So this is that approach that you have to follow.
And this is exactly what I mean.
In quoting now, you have to perform, you have to perform this approach for each and every feature.
So here I am going to say I have to just perform this at.
For each and every feature here, I have to say, this gets replaced by basically my column, that's
it.
Now, what I have to do, basically, let's say I have to print something, Sarah.
I'm going to say just print it.
And let's say after printing to make it more user friendly, you can add some spaces as well.
I'm just going to add and just going to execute, you will see with respect to all that, you have that
much value with respect to resort hotel, you have that much value and all this sort of thing.
Now, what you have to do basically here, you have to simply convert all these stuffs into a dictionary.
Now, the question that you guys can ask or is a query.
Yeah.
Why why there is a need to convert this.
All this is just introduction because you have to map you that our city hotel.
I have to map this value.
And once you will create a dictionary now data is in the form of key value pairs.
It means the sea city hotels become key and this becomes value.
So once you have all this stuff in your dictionary, you can easily map that.
That's the power of dictionary.
So here I am going to say I have to convert all this stuff into the city.
Just called to underscore DECT over there.
And again, I'm going to execute it now.
You will see you have all these stuffs available over here.
All this is now simple.
It's simple.
Now you have to just you have to just map it.
So far, this is what I'm going to do.
Let's say this time I don't have to pay Latza this time.
This is exactly my dictionary with respect to each and every column.
So here I going to say this is exactly my dictionary.
Once I have all this stuff, what I have to do, I have to just map it.
So for this, I'm going to say data on the score, get off column, dot the map.
I have to map what my dictionary is simple.
Then I have to update my net column as well.
So data and a score get of column equals to this one index.
It just executed.
It will take a time.
And again, if I'm going to call my head over there now, you will figure out all your string data gets
converted into some the values and your machine learning model now able to understand internally what
exactly the meaning of this, because machine learning how to understand is Janita.
So if you guys are not that much comfort level about this, meaning coding, you can definitely raise
your credit in your section or you can personally text me as well.
So I hope you will love this approach as well.
There are tons of approaches to convert this into something into the format, like the label encoding
and all these things.
But here I'm going to show you some advance support, because whenever you are going to work on some
real work data there, you have to use some advanced approach.
You don't have to use some approach like dummy approaches.
Now, what you have to do, you need your entire data frame in which you have all the numerical features
in which we have all the categorical features.
So for this, what I'm going to do, I'm just going to concatenate my two data.
So here I'm going to say in this data underscore get and after it, I have something.
So here I am going to say data of num underscore features.
After having all this stuff, I have to mention something my access equals to one, because here I'm
going to say I have to concatenate in vertical fashion after doing all this stuff.
Let me summarize.
Let's say this is my entire data.
I'm going to say this is own data frame.
Just execute this cell.
And if I'm going to call this data frame, Dot had to get a quick overview of how my data frame looks
like.
Now, you will see these are exactly all the features that I have over here.
And you will see over here there are two features that are going to repeat it, which are exactly this
cancellation and cancel it means you can drop any one of them.
So for this, I'm just going to say data frame, dot drop.
I have to drop what I have to do up.
I have to drop this feature the symbol then I have to access equals to one because I have to remove
in a vertical way.
Then I'm going to say I have to update it as well.
So in place equals to true.
Just execute all this just gets executed.
And if I'm going to call my data or shape forward here now, you will see it has that much number of
rows and it has that much number of columns.
So that's all about the session.
In the upcoming session, we are going to decide what exactly the outline, how to handle outlier situations
in your data.
So who.
Discussion very much, and you still have a query you can feel free to ask, just raise in your section
or you can personally text me as well.
So thank you.
Have a nice day.
Keep learning.
Keep growing.
Keep practicing.