Class FeatureUnion<T>
- Namespace
- AiDotNet.Preprocessing
- Assembly
- AiDotNet.dll
Concatenates results from multiple transformers horizontally.
public class FeatureUnion<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
-
FeatureUnion<T>
- Implements
- Inherited Members
Remarks
FeatureUnion applies multiple transformers to the same input data and concatenates their outputs into a single feature matrix. This is useful for combining different feature extraction methods.
Each transformer receives the full input matrix and produces its own output. All outputs are then concatenated column-wise.
For Beginners: Sometimes you want multiple feature sets from the same data: - Polynomial features from numeric columns - Statistics (mean, std) from time windows - Both PCA and manual feature engineering
FeatureUnion runs all transformers and combines their outputs side by side.
Constructors
FeatureUnion()
Creates a new instance of FeatureUnion<T>.
public FeatureUnion()
Properties
SupportsInverseTransform
Gets whether this transformer supports inverse transformation.
public override bool SupportsInverseTransform { get; }
Property Value
Methods
Add(IDataTransformer<T, Matrix<T>, Matrix<T>>)
Adds a transformer to the union.
public FeatureUnion<T> Add(IDataTransformer<T, Matrix<T>, Matrix<T>> transformer)
Parameters
transformerIDataTransformer<T, Matrix<T>, Matrix<T>>The transformer to add.
Returns
- FeatureUnion<T>
This instance for method chaining.
Add(string, IDataTransformer<T, Matrix<T>, Matrix<T>>)
Adds a transformer to the union.
public FeatureUnion<T> Add(string name, IDataTransformer<T, Matrix<T>, Matrix<T>> transformer)
Parameters
namestringName identifier for the transformer.
transformerIDataTransformer<T, Matrix<T>, Matrix<T>>The transformer to add.
Returns
- FeatureUnion<T>
This instance for method chaining.
FitCore(Matrix<T>)
Fits all transformers to the input data.
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.
GetTransformerOutputWidths()
Gets the number of output features from each transformer.
public Dictionary<string, int> GetTransformerOutputWidths()
Returns
- Dictionary<string, int>
Dictionary mapping transformer name to output width.
InverseTransformCore(Matrix<T>)
Inverse transformation is not supported for FeatureUnion.
protected override Matrix<T> InverseTransformCore(Matrix<T> data)
Parameters
dataMatrix<T>
Returns
- Matrix<T>
TransformCore(Matrix<T>)
Transforms the data by applying all transformers and concatenating outputs.
protected override Matrix<T> TransformCore(Matrix<T> data)
Parameters
dataMatrix<T>The data to transform.
Returns
- Matrix<T>
The concatenated transformed features.