One Hot encoding — categorical to numerical

Machine learning models need numbers, not text. One-hot encoding converts categories like gender or color into separate binary columns: a gender column becomes two columns of 0s and 1s. High-cardinality features like zip codes create many columns and slow down models.
Chapters
So we all know our computers can understand 0 and 1, our machine can understand numbers very well. That is why we have to focus on converting any categorical data into numbers. Yes. So whenever we get a dataset, we have number values as well and we have categorical values as well. Categorical means where we have like text. When I talk about male, female, red, blue, green, any color, any name, any person's last name, address, anything it could be, right? So we have to focus on converting that categorical data into numeric data. How to do that? We have to use a technique called one-hot encoding. Now what is one-hot encoding in simple terms? The way of converting any categorical data into numerical one. How to do it? To implement it, you do not have to do much, but you have to use the pandas library and get_dummies function. This get_dummies function will implement the categorical to numeric conversion. Now you have to fill in which column do you want to work with. Now how does it convert? So let's say, let's consider a gender column where we have two values, right? Male and female, right? So for male and female, what will it do is it will create two separate columns, right? Earlier it was just one gender column with male and female, but now it will create two separate column and will name it as gender M, and then we'll name it as gender F. Now this gender M or F will be having zeros and ones. So wherever in whichever column it was male, it will fill in with 1, another with the 0. Then again, if it was female, then 0 and 1. So basically 0, 1, 0, 1 will be the combination which you will find in your entire data, and multiple columns will be created. For that reason, I have created two dummies, one with a high cardinality, next with a low cardinality.










