Class HelmertEncoder<T>
- Namespace
- AiDotNet.Preprocessing.Encoders
- Assembly
- AiDotNet.dll
Encodes categorical features using Helmert coding.
public class HelmertEncoder<T> : TransformerBase<T, Matrix<T>, Matrix<T>>, IDataTransformer<T, Matrix<T>, Matrix<T>>
Type Parameters
TThe numeric type for calculations (e.g., float, double).
- Inheritance
-
HelmertEncoder<T>
- Implements
- Inherited Members
Remarks
HelmertEncoder compares each level of a categorical variable to the mean of all subsequent levels. This is useful when you want to understand how each level differs from the average of all levels that come after it.
For k categories, creates k-1 columns. Column i compares level i to the mean of levels i+1 through k.
For Beginners: Helmert coding is useful when order matters: - Compares each level to the "future average" - First level vs. average of all others - Second level vs. average of third, fourth, etc. - Good for detecting trends or cumulative effects
Constructors
HelmertEncoder(HelmertHandleUnknown, bool, int[]?)
Creates a new instance of HelmertEncoder<T>.
public HelmertEncoder(HelmertHandleUnknown handleUnknown = HelmertHandleUnknown.UseZeros, bool reversed = false, int[]? columnIndices = null)
Parameters
handleUnknownHelmertHandleUnknownHow to handle unknown categories. Defaults to UseZeros.
reversedboolIf true, compare each level to mean of previous levels. Defaults to false.
columnIndicesint[]The column indices to encode, or null for all columns.
Properties
HandleUnknown
Gets how unknown categories are handled.
public HelmertHandleUnknown HandleUnknown { get; }
Property Value
NOutputFeatures
Gets the number of output features.
public int NOutputFeatures { get; }
Property Value
Reversed
Gets whether reversed Helmert coding is used.
public bool Reversed { get; }
Property Value
SupportsInverseTransform
Gets whether this transformer supports inverse transformation.
public override bool SupportsInverseTransform { get; }
Property Value
Methods
FitCore(Matrix<T>)
Fits the encoder by learning categories and building contrast matrices.
protected override void FitCore(Matrix<T> data)
Parameters
dataMatrix<T>
GetFeatureNamesOut(string[]?)
Gets the output feature names after transformation.
public override string[] GetFeatureNamesOut(string[]? inputFeatureNames = null)
Parameters
inputFeatureNamesstring[]
Returns
- string[]
InverseTransformCore(Matrix<T>)
Inverse transformation is not supported.
protected override Matrix<T> InverseTransformCore(Matrix<T> data)
Parameters
dataMatrix<T>
Returns
- Matrix<T>
TransformCore(Matrix<T>)
Transforms the data using Helmert coding.
protected override Matrix<T> TransformCore(Matrix<T> data)
Parameters
dataMatrix<T>
Returns
- Matrix<T>