#machinelearning

Machine learning

A technique for transforming categorical parameters into vectors. We take each of the categories and transform the values in vectors of boolean values where all are zeroes excepting the one for the category the feature belongs to.

This is why it is called one hot encoding. All values are zero excepting the value for "HOT" that is one.

For example, the values of categories of a feature:

UP
DOWN
LEFT
UP
RIGHT

can turn into

[0, 0, 0, 1]
[0, 0, 1, 0]
[0, 1, 0, 0]
[0, 0, 0, 1]
[1, 0, 0, 0]

assuming those are the only 4 categories.

Using sklearn we can do

from sklearn.preprocessing import OrdinalEncoder

ordinal_encoder = OrdinalEncoder()
housing_cat_encoded = ordinal_encoder.fit_transform(housing_cat)