BinaryEncoder<T>
Models & Types · AiDotNet.Preprocessing.Encoders
Encodes categorical features using binary representation.
Inheritance: TransformerBase<T, Matrix<T>, Matrix<T>> → BinaryEncoder<T>
For Beginners
If you have 8 categories, one-hot creates 8 columns. Binary encoding uses only 3 columns (since 8 = 2^3):
- Category 0 → [0, 0, 0]
- Category 1 → [0, 0, 1]
- Category 2 → [0, 1, 0]
- Category 7 → [1, 1, 1]
This is useful for high-cardinality categorical features where one-hot would create too many columns.
How It Works
BinaryEncoder first ordinal encodes the categories, then converts those integers to their binary representation. This creates log2(n) columns instead of n columns that one-hot encoding would create.
Constructors
| Constructor | Summary |
|---|---|
BinaryEncoder(BinaryEncoderHandleUnknown handleUnknown, int[] columnIndices) |
Creates a new instance of BinaryEncoder. |
Properties
| Property | Summary |
|---|---|
BinaryEncoderHandleUnknown HandleUnknown { get; } |
Gets how unknown categories are handled. |
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. |