Table of Contents

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

T

The numeric type for calculations (e.g., float, double).

Inheritance
TransformerBase<T, Matrix<T>, Matrix<T>>
HelmertEncoder<T>
Implements
IDataTransformer<T, Matrix<T>, Matrix<T>>
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

handleUnknown HelmertHandleUnknown

How to handle unknown categories. Defaults to UseZeros.

reversed bool

If true, compare each level to mean of previous levels. Defaults to false.

columnIndices int[]

The column indices to encode, or null for all columns.

Properties

HandleUnknown

Gets how unknown categories are handled.

public HelmertHandleUnknown HandleUnknown { get; }

Property Value

HelmertHandleUnknown

NOutputFeatures

Gets the number of output features.

public int NOutputFeatures { get; }

Property Value

int

Reversed

Gets whether reversed Helmert coding is used.

public bool Reversed { get; }

Property Value

bool

SupportsInverseTransform

Gets whether this transformer supports inverse transformation.

public override bool SupportsInverseTransform { get; }

Property Value

bool

Methods

FitCore(Matrix<T>)

Fits the encoder by learning categories and building contrast matrices.

protected override void FitCore(Matrix<T> data)

Parameters

data Matrix<T>

GetFeatureNamesOut(string[]?)

Gets the output feature names after transformation.

public override string[] GetFeatureNamesOut(string[]? inputFeatureNames = null)

Parameters

inputFeatureNames string[]

Returns

string[]

InverseTransformCore(Matrix<T>)

Inverse transformation is not supported.

protected override Matrix<T> InverseTransformCore(Matrix<T> data)

Parameters

data Matrix<T>

Returns

Matrix<T>

TransformCore(Matrix<T>)

Transforms the data using Helmert coding.

protected override Matrix<T> TransformCore(Matrix<T> data)

Parameters

data Matrix<T>

Returns

Matrix<T>