CatBoostEncoder<T>
Models & Types · AiDotNet.Preprocessing.Encoders
Encodes categorical features using ordered (CatBoost-style) target encoding.
Inheritance: TransformerBase<T, Matrix<T>, Matrix<T>> → CatBoostEncoder<T>
For Beginners
Regular target encoding can “cheat” by using future information. CatBoost encoding prevents this:
- When encoding row 10, it only uses data from rows 1-9
- Row 1 always gets the prior (global mean) since there’s nothing before it
- This prevents overfitting and works better with gradient boosting
How It Works
CatBoostEncoder applies an ordered approach to target encoding that prevents target leakage by only using target values from previous samples when encoding. This is the same technique used in the CatBoost gradient boosting library.
For each sample, the encoding is computed as: (sum of targets for previous samples with same category + prior) / (count + 1)
Constructors
| Constructor | Summary |
|---|---|
CatBoostEncoder(double prior, CatBoostHandleUnknown handleUnknown, int randomState, int[] columnIndices) |
Creates a new instance of CatBoostEncoder. |
Properties
| Property | Summary |
|---|---|
CatBoostHandleUnknown HandleUnknown { get; } |
Gets how unknown categories are handled. |
T GlobalMean { get; } |
Gets the global target mean. |
bool SupportsInverseTransform { get; } |
Gets whether this transformer supports inverse transformation. |
double Prior { get; } |
Gets the prior value (regularization). |
Methods
| Method | Summary |
|---|---|
Matrix<T> FitTransform(Matrix<T> data, Vector<T> target) |
Fits and transforms using ordered target encoding (CatBoost style). |
Matrix<T> TransformWithTarget(Matrix<T> data, Vector<T> target) |
Transforms training data using ordered encoding (only uses previous samples). |
string[] GetFeatureNamesOut(string[] inputFeatureNames) |
Gets the output feature names after transformation. |
void Fit(Matrix<T> data, Vector<T> target) |
Fits the encoder by computing category statistics. |