Hello,
I am Mohit, from LearnVern.( 6 seconds pause ; music )
This tutorial is a continuation from our previous session of Machine learning Course.
So, let's start,
In this Practical, we will see two things,
I will mention them here,
First thing is Label Encoder,
as to How LabelEncoder works.
And, second is How Does One Hot Encoder Works.
we are going to see these two.( 3 Seconds pause :typing)
So, let's begin with Label Encoder
For label Encoder, the first thing that I will have to do is import Library.
So, to import Library,
'from sk learn.. import… preprocessing'.
So, this Library will be provided to me from Label Encoder.
Here an error came, 'no module found',
let me correct it, 'sklearn'. ( 5 seconds pause ;typing)
Ok!
(01/18)
Now, with the help of preprocessing I will import label Encoder, or you can also say create an object.
So, here I will write label Encoder in short form as L E and here preprocessing… and dot,
as soon as I put dot, it will start giving me suggestions,
you can see here label binarizer, encoder,
here, we got our encoder.
And with the help of brackets I will create an object.
This is the object formed for my label Encoder.
Now, I will have to add data,
for which, I will have to first upload the data.
But we are not going to do that at the moment.
So, this time we will create a data frame with the help of pandas library, so,
Import pandas as P D.
And from here, with the help of pandas data frame method i.e "data is equal to P D dot dataframe",
we will create a data frame.
And, here I will pass a dictionary,
So, the example that we had seen earlier in the presentation, we will use the same example here also, so that you can understand it easily.
So, in the brackets here I am taking the example of animals,
So for animals I am writing the list,
Our first animal was cat
Second was the dog, and the third was horse.
Here, I have taken all three.
Let's check our data first, by displaying it as to how it is uploaded.
you can see 'animals',
At zero there is 'cat'
At 1 there is 'dog'
At 2 there is 'horse'.
So, my data is also loaded now.
Now, I will pass this data to the object of my label Encoder L E, over here and pass it.
So, to pass this, there is a method called, 'le dot f i t'.
In this fit method, we pass our data.
I have passed my data on this.
Now, with the next step I will get my encoded data.
So, here I will type
'e n c o d e d, encoded underscore data', over here.
Encoded underscore data is equal to L E dot.
Now, I will have to transform the data.
Which data will we have to transform?
The same original data that we had, but in the encoded form.
Let's see what has come in encoded data?
In the encoded data we can see 0,1 and 2 has come,
So, what is this 0,1,2
O is for cat
1 is for dog,
And
2 for 'horse'
In this way, our Encoding is done here
(04/15)
Now, you see How our next Encoding is done?
That is our One Hot Encoding
Where we had seen, it assigns binary values.
So, one hot Encoding also is a sub package that we can get from sk learn.
So, now we will move ahead on our second part, which is of one hot encoding.
'o h e, one hot encoding is equal to',
here with the help of preprocessing, dot one hot encoding,
so here I have created an object with one hot encoder.
here, I am going to pass the same dataset to this also,
So, the name of the method is also same i.e
O h e dot fit, and here I have passed the data.
After this we will have to get the encoded data,
So, I will write encoded o h e d a t a, data
So, in this I am going to pass o h e dot transform method…
Here, I will pass the data and try to understand by executing it.
So, I will convert the encoded data or encoded o h e data into an array, so that it becomes easier for us to understand.
So, here you can see, it has given me the result in the form of
1,0,0 (one zero zero)
0,1,0 (zero one zero)
0,0,1 (zero zero one)
what is the exact meaning of this? I will explain it to you.
here, I will paste the entire output in the paint window
Now, you can see in front of you, that the output given by our algorithm is pasted over here.
So, now I will go up here and check our original dataset.
Here, we have cat, dog and horse.
Now, I will explain you how, this has happened
So, here it is exactly like we understood it before where,
on zero location we had cat,
And, on first location we had dog,
And, at the second location we had 'horse'
here, this is a zero cell,
Here, it is first cell, and
(06/24)
Lastly, we have a second cell here.
So at zero location we have a cat, so here 1 is present over here,it is representing a cat.
Next, first is representing 'dog', so in this column over here it is written 1 which is representing dog.
Last,second is representing horse, so, over here at last it is 1 over here which is representing 2 i.e horse.
So, in one hot encoding, wherever there is 1, we consider that variable to be present.
And wherever there are zero, we consider that variable as absent.
Here zero, zero meaning cat and dog are absent, and one meaning horse is present.
In this way, we understood how label Encoding and one hot encoding is done.
remain excited… We are going to see more such programmes.
friends, let's conclude today.
We will stop our session here, and see it's further sessions in the next part.
So till then keep learning and remain motivated.
Thank you.
If you have any queries or comments, click the discussion button below the video and post there. This way, you will be able to connect to fellow learners and discuss the course. Also, Our Team will try to solve your query.
Share a personalized message with your friends.