JamesSteinEncoder<T>
Models & Types ยท AiDotNet.Preprocessing.Encoders
Encodes categorical features using James-Stein shrinkage estimation.
Inheritance: TransformerBase<T, Matrix<T>, Matrix<T>> โ JamesSteinEncoder<T>
For Beginners
This encoder balances between:
- Trusting category-specific averages (when we have lots of data)
- Falling back to the overall average (when category data is sparse)
- The balance is determined automatically using statistical theory
How It Works
JamesSteinEncoder uses Bayesian shrinkage to blend category-specific target means with the global mean. Categories with more samples get weights closer to their own mean, while rare categories shrink toward the global mean.
The shrinkage formula: encoded = (1 - B) * category_mean + B * global_mean where B is the shrinkage factor based on sample size and variance.
Constructors
| Constructor | Summary |
|---|---|
JamesSteinEncoder(JamesSteinHandleUnknown handleUnknown, int[] columnIndices) |
Creates a new instance of JamesSteinEncoder. |
Properties
| Property | Summary |
|---|---|
JamesSteinHandleUnknown 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. |
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 James-Stein shrinkage estimates. |