HashingEncoder<T>
Models & Types · AiDotNet.Preprocessing.Encoders
Encodes categorical features using feature hashing (hashing trick).
Inheritance: TransformerBase<T, Matrix<T>, Matrix<T>> → HashingEncoder<T>
For Beginners
Instead of creating one column per category:
- Hash encoding creates a fixed number of columns (e.g., 8)
- Each category is hashed to one of these columns
- Multiple categories may share the same column (collision)
Pros: Fixed memory, handles new categories, fast Cons: Information loss from collisions, not reversible
How It Works
HashingEncoder uses a hash function to map categories to a fixed number of columns. This is useful for high-cardinality categorical features where one-hot encoding would create too many columns.
Unlike other encoders, HashingEncoder doesn’t need to store the category mappings, making it memory-efficient and able to handle previously unseen categories.
Constructors
| Constructor | Summary |
|---|---|
HashingEncoder(int nComponents, bool alternateSign, int[] columnIndices) |
Creates a new instance of HashingEncoder. |
Properties
| Property | Summary |
|---|---|
bool AlternateSign { get; } |
Gets whether alternate signs are used for hash collisions. |
bool SupportsInverseTransform { get; } |
Gets whether this transformer supports inverse transformation. |
int NComponents { get; } |
Gets the number of hash components (output features per encoded column). |
Methods
| Method | Summary |
|---|---|
string[] GetFeatureNamesOut(string[] inputFeatureNames) |
Gets the output feature names after transformation. |