Table of Contents

Class ColumnTransformer<T>

Namespace
AiDotNet.Preprocessing
Assembly
AiDotNet.dll

Applies different transformers to different columns of the input.

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

Remarks

ColumnTransformer allows you to specify which transformer should be applied to which columns. This is useful when different columns require different preprocessing (e.g., scaling numeric columns, encoding categorical columns).

Output columns are concatenated in the order transformers are added. Columns not specified in any transformer can be passed through or dropped.

For Beginners: Different columns often need different treatment: - Numeric columns: scaling, normalization - Categorical columns: one-hot encoding - Text columns: vectorization

ColumnTransformer lets you apply the right transformation to each column type.

Constructors

ColumnTransformer(ColumnTransformerRemainder)

Creates a new instance of ColumnTransformer<T>.

public ColumnTransformer(ColumnTransformerRemainder remainder = ColumnTransformerRemainder.Drop)

Parameters

remainder ColumnTransformerRemainder

How to handle columns not specified in any transformer. Defaults to Drop.

Properties

Remainder

Gets how columns not specified in any transformer are handled.

public ColumnTransformerRemainder Remainder { get; }

Property Value

ColumnTransformerRemainder

SupportsInverseTransform

Gets whether this transformer supports inverse transformation.

public override bool SupportsInverseTransform { get; }

Property Value

bool

Methods

Add(IDataTransformer<T, Matrix<T>, Matrix<T>>, int[])

Adds a transformer to be applied to specific columns.

public ColumnTransformer<T> Add(IDataTransformer<T, Matrix<T>, Matrix<T>> transformer, int[] columns)

Parameters

transformer IDataTransformer<T, Matrix<T>, Matrix<T>>

The transformer to apply.

columns int[]

The column indices to apply this transformer to.

Returns

ColumnTransformer<T>

This instance for method chaining.

Add(string, IDataTransformer<T, Matrix<T>, Matrix<T>>, int[])

Adds a transformer to be applied to specific columns.

public ColumnTransformer<T> Add(string name, IDataTransformer<T, Matrix<T>, Matrix<T>> transformer, int[] columns)

Parameters

name string

Name identifier for the transformer.

transformer IDataTransformer<T, Matrix<T>, Matrix<T>>

The transformer to apply.

columns int[]

The column indices to apply this transformer to.

Returns

ColumnTransformer<T>

This instance for method chaining.

FitCore(Matrix<T>)

Fits all transformers to their respective columns.

protected override void FitCore(Matrix<T> data)

Parameters

data Matrix<T>

The training data matrix.

GetFeatureNamesOut(string[]?)

Gets the output feature names after transformation.

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

Parameters

inputFeatureNames string[]

Returns

string[]

GetTransformer(string)

Gets the transformer with the specified name.

public IDataTransformer<T, Matrix<T>, Matrix<T>>? GetTransformer(string name)

Parameters

name string

The transformer name.

Returns

IDataTransformer<T, Matrix<T>, Matrix<T>>

The transformer if found, null otherwise.

GetTransformerNames()

Gets all transformer names.

public string[] GetTransformerNames()

Returns

string[]

Array of transformer names.

InverseTransformCore(Matrix<T>)

Inverse transformation is not supported for ColumnTransformer.

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

Parameters

data Matrix<T>

Returns

Matrix<T>

TransformCore(Matrix<T>)

Transforms the data by applying each transformer to its columns.

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

Parameters

data Matrix<T>

The data to transform.

Returns

Matrix<T>

The transformed data with all outputs concatenated.