Table of Contents

Class BackwardDifferenceEncoder<T>

Namespace
AiDotNet.Preprocessing.Encoders
Assembly
AiDotNet.dll

Encodes categorical features using backward difference coding.

public class BackwardDifferenceEncoder<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>>
BackwardDifferenceEncoder<T>
Implements
IDataTransformer<T, Matrix<T>, Matrix<T>>
Inherited Members

Remarks

BackwardDifferenceEncoder compares each level of a categorical variable to the previous level. This is useful for ordinal variables where the difference between adjacent levels is meaningful.

For k categories, creates k-1 columns. Each column represents the difference between level n and level n-1.

For Beginners: Backward difference coding is useful for ordinal data: - Education: High School vs Some College vs Bachelor's vs Master's - Each coefficient shows the "step up" from the previous level - Good when you expect gradual progression through levels

Constructors

BackwardDifferenceEncoder(BackwardDifferenceHandleUnknown, int[]?)

Creates a new instance of BackwardDifferenceEncoder<T>.

public BackwardDifferenceEncoder(BackwardDifferenceHandleUnknown handleUnknown = BackwardDifferenceHandleUnknown.UseZeros, int[]? columnIndices = null)

Parameters

handleUnknown BackwardDifferenceHandleUnknown

How to handle unknown categories. Defaults to UseZeros.

columnIndices int[]

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

Properties

HandleUnknown

Gets how unknown categories are handled.

public BackwardDifferenceHandleUnknown HandleUnknown { get; }

Property Value

BackwardDifferenceHandleUnknown

NOutputFeatures

Gets the number of output features.

public int NOutputFeatures { get; }

Property Value

int

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 backward difference coding.

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

Parameters

data Matrix<T>

Returns

Matrix<T>