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
TThe numeric type for calculations (e.g., float, double).
- Inheritance
-
BackwardDifferenceEncoder<T>
- Implements
- 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
handleUnknownBackwardDifferenceHandleUnknownHow to handle unknown categories. Defaults to UseZeros.
columnIndicesint[]The column indices to encode, or null for all columns.
Properties
HandleUnknown
Gets how unknown categories are handled.
public BackwardDifferenceHandleUnknown HandleUnknown { get; }
Property Value
NOutputFeatures
Gets the number of output features.
public int NOutputFeatures { 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 backward difference coding.
protected override Matrix<T> TransformCore(Matrix<T> data)
Parameters
dataMatrix<T>
Returns
- Matrix<T>