CountEncoder<T>

Models & Types · AiDotNet.Preprocessing.Encoders

Encodes categorical features using frequency counts.

Inheritance: TransformerBase<T, Matrix<T>, Matrix<T>> → CountEncoder<T>

For Beginners

Instead of creating multiple columns, frequency encoding replaces each category with how often it appears:

  • Category “common” appearing 1000 times → 1000 (or 0.5 if normalized)
  • Category “rare” appearing 10 times → 10 (or 0.005 if normalized)

This is useful when the popularity of a category is predictive of the target.

How It Works

CountEncoder replaces each category with its frequency count (number of occurrences) in the training data. This creates a continuous feature that captures category popularity.

Options include normalizing counts to probabilities (0-1 range) or log-transforming the counts to handle highly skewed distributions.

Constructors

Constructor Summary
CountEncoder(bool normalize, bool logTransform, CountEncoderHandleUnknown handleUnknown, double unknownValue, int[] columnIndices) Creates a new instance of CountEncoder.

Properties

Property Summary
CountEncoderHandleUnknown HandleUnknown { get; } Gets how unknown categories are handled.
Dictionary<int, CategoryValueMap<T>> CountMaps { get; } Gets the count maps for each column.
bool LogTransform { get; } Gets whether counts are log-transformed.
bool Normalize { get; } Gets whether counts are normalized to probabilities.
bool SupportsInverseTransform { get; } Gets whether this transformer supports inverse transformation.

Methods

Method Summary
string[] GetFeatureNamesOut(string[] inputFeatureNames) Gets the output feature names after transformation.