OneHotEncoder<T>
Models & Types · AiDotNet.Preprocessing.Encoders
Encodes categorical values as one-hot (binary) vectors.
Inheritance: TransformerBase<T, Matrix<T>, Matrix<T>> → OneHotEncoder<T>
For Beginners
This encoder converts categories into binary columns:
- Each unique value gets its own column
- A 1 indicates the category is present, 0 means it’s not
Example for colors [red, green, blue, red]: Becomes: [1, 0, 0] (red) [0, 1, 0] (green) [0, 0, 1] (blue) [1, 0, 0] (red)
How It Works
OneHotEncoder transforms categorical values into binary indicator columns. Each unique category value becomes a separate column with 1s and 0s indicating presence. This encoding is required for many machine learning algorithms that cannot work directly with categories.
Constructors
| Constructor | Summary |
|---|---|
OneHotEncoder(bool dropFirst, OneHotUnknownHandling handleUnknown, int[] columnIndices) |
Creates a new instance of OneHotEncoder. |
Properties
| Property | Summary |
|---|---|
List<Vector<T>> Categories { get; } |
Gets the categories for each encoded column. |
OneHotUnknownHandling HandleUnknown { get; } |
Gets how unknown categories are handled. |
bool DropFirst { get; } |
Gets whether the first category is dropped (to avoid multicollinearity). |
bool SupportsInverseTransform { get; } |
Gets whether this transformer supports inverse transformation. |
int NOutputFeatures { get; } |
Gets the number of output features after transformation. |
Methods
| Method | Summary |
|---|---|
string[] GetFeatureNamesOut(string[] inputFeatureNames) |
Gets the output feature names after transformation. |