Ordinal Encoding
tags: #python/data_science/preprocessing
What is ordinal encoding?
In ordinal encoding, each unique category value is assigned an integer value.
AKA integer encoding and is easily reversible.
The output range of OrdinalEncoder depends on the number of categories in each feature being encoded. If a feature has n unique categories, the output range will be from 0 to n-1.
For ordinal features, the integer values have a natural ordered relationship between each other and machine learning algorithms may be able to understand and harness this relationship.
Numerical values to each category in a variable based on their order or rank. Therefore, the function assumes an order or rank among the categories.
Sample code
# import OrdinalEncoder
from sklearn.preprocessing import OrdinalEncoder
# create instance of the encoder object
encoder = OrdinalEncoder()
# transform data
df['COLNAME'] = encoder.fit_transform(['COLNAME']) # can pass a list