OrdinalEncoder<T>
Models & Types · AiDotNet.Preprocessing.Encoders
Encodes categorical values as ordinal integers with optional custom ordering.
Inheritance: TransformerBase<T, Matrix<T>, Matrix<T>> → OrdinalEncoder<T>
For Beginners
This encoder converts categories to ordered numbers:
- You can specify the order of categories
- Useful when categories have a natural ordering (e.g., low, medium, high)
Example with custom order [“small”, “medium”, “large”]: [“large”, “small”, “medium”, “large”] → [2, 0, 1, 2]
How It Works
OrdinalEncoder transforms categorical values to consecutive integers based on order. Unlike LabelEncoder, it can accept custom category orderings and handle unknown values.
Constructors
| Constructor | Summary |
|---|---|
OrdinalEncoder(List<Vector<T>> categories, UnknownValueHandling handleUnknown, double unknownValue, int[] columnIndices) |
Creates a new instance of OrdinalEncoder. |
Properties
| Property | Summary |
|---|---|
UnknownValueHandling HandleUnknown { get; } |
Gets how unknown categories are handled. |
bool SupportsInverseTransform { get; } |
Gets whether this transformer supports inverse transformation. |
double UnknownValue { get; } |
Gets the value used for unknown categories. |
Methods
| Method | Summary |
|---|---|
string[] GetFeatureNamesOut(string[] inputFeatureNames) |
Gets the output feature names after transformation. |