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
TThe numeric type for calculations (e.g., float, double).
- Inheritance
-
ColumnTransformer<T>
- Implements
- 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
remainderColumnTransformerRemainderHow 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
SupportsInverseTransform
Gets whether this transformer supports inverse transformation.
public override bool SupportsInverseTransform { get; }
Property Value
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
transformerIDataTransformer<T, Matrix<T>, Matrix<T>>The transformer to apply.
columnsint[]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
namestringName identifier for the transformer.
transformerIDataTransformer<T, Matrix<T>, Matrix<T>>The transformer to apply.
columnsint[]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
dataMatrix<T>The training data matrix.
GetFeatureNamesOut(string[]?)
Gets the output feature names after transformation.
public override string[] GetFeatureNamesOut(string[]? inputFeatureNames = null)
Parameters
inputFeatureNamesstring[]
Returns
- string[]
GetTransformer(string)
Gets the transformer with the specified name.
public IDataTransformer<T, Matrix<T>, Matrix<T>>? GetTransformer(string name)
Parameters
namestringThe 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
dataMatrix<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
dataMatrix<T>The data to transform.
Returns
- Matrix<T>
The transformed data with all outputs concatenated.