MEstimateEncoder<T>
Models & Types · AiDotNet.Preprocessing.Encoders
Encodes categorical features using M-estimate regularization.
Inheritance: TransformerBase<T, Matrix<T>, Matrix<T>> → MEstimateEncoder<T>
For Beginners
M-estimate is like adding ‘m’ fake samples:
- Each fake sample has the global mean as its target
- Categories with few samples get pulled toward the global mean
- Categories with many samples stay close to their actual mean
- Higher m = more smoothing toward global mean
How It Works
MEstimateEncoder applies M-estimate smoothing to target encoding, which adds a regularization parameter ‘m’ that controls shrinkage toward the global mean.
The formula: encoded = (n * category_mean + m * global_mean) / (n + m) where n is the count of samples in the category and m is the smoothing parameter.
Constructors
| Constructor | Summary |
|---|---|
MEstimateEncoder(double m, MEstimateHandleUnknown handleUnknown, int[] columnIndices) |
Creates a new instance of MEstimateEncoder. |
Properties
| Property | Summary |
|---|---|
MEstimateHandleUnknown 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 M { get; } |
Gets the smoothing parameter m. |
Methods
| Method | Summary |
|---|---|
Matrix<T> FitTransform(Matrix<T> data, Vector<T> target) |
Fits and transforms the data. |
string[] GetFeatureNamesOut(string[] inputFeatureNames) |
Gets the output feature names after transformation. |
void Fit(Matrix<T> data, Vector<T> target) |
Fits the encoder by computing M-estimate encodings. |