OrdinalEncoder
noun
say it: “OR-dih-nul en-KOH-der” /ˈɔrdənəl ɛnˈkoʊdər/
A scikit-learn tool that replaces each category in a column with a whole number, in a set order.
What is OrdinalEncoder?
OrdinalEncoder is scikit-learn's tool that turns each category into one number: 0, 1, 2 and so on. It suits
categories with a real order, such as small, medium and large, given with categories=; for categories with no order,
one-hot encoding is safer.
from sklearn.preprocessing import OrdinalEncoder
encoder = OrdinalEncoder(categories=[["small", "medium", "large"]])
print(encoder.fit_transform([["large"], ["small"], ["medium"]]).ravel()) # [2. 0. 1.]
In a sentence
- “Using an OrdinalEncoder on species would have told the model rabbits come after dogs.”
- “The OrdinalEncoder turned small, medium and large into 0, 1 and 2.”
Level: Journeyman · More Python terms at this level
Updated