- 5
Can anyone explain one hot encoding
Sklearn in python
2 Answers
0
One hot encoding is an encoding method for categorical features. Let's say your data has a column containing 3 different values: a, b, and c.
One hot encoding replaces this column with 3 new columns: 1 column for value a, 1 column for value b, one column for value c. The value in the corresponding column will be set to 1, the remaining values will be set to 0.
a -> 100
b -> 010
c -> 001
This is usually necessary for models that are not based on trees, because they do not handle categorical data well. For example k-nearest-neighbors, regression, and support vector machines.
0
Thanks but how do you implement it in sklearn? step by step code in python