Class PreprocessingPipeline<T, TInput, TOutput>
- Namespace
- AiDotNet.Preprocessing
- Assembly
- AiDotNet.dll
Chains multiple data transformers into a sequential pipeline.
public class PreprocessingPipeline<T, TInput, TOutput> : IDataTransformer<T, TInput, TOutput>
Type Parameters
TThe numeric type for calculations.
TInputThe input data type.
TOutputThe output data type.
- Inheritance
-
PreprocessingPipeline<T, TInput, TOutput>
- Implements
-
IDataTransformer<T, TInput, TOutput>
- Inherited Members
Remarks
A preprocessing pipeline applies transformers in sequence, passing the output of each transformer as input to the next. This enables composable preprocessing workflows similar to sklearn's Pipeline.
For Beginners: Think of a pipeline as a series of steps. For example: 1. First, fill in missing values (SimpleImputer) 2. Then, scale the data (StandardScaler) 3. Finally, create polynomial features (PolynomialFeatures)
The pipeline ensures all these steps happen in the right order.
Constructors
PreprocessingPipeline()
Creates a new empty preprocessing pipeline.
public PreprocessingPipeline()
Properties
ColumnIndices
Gets the column indices this transformer operates on (null for pipelines).
public int[]? ColumnIndices { get; }
Property Value
- int[]
Count
Gets the number of steps in the pipeline.
public int Count { get; }
Property Value
IsFitted
Gets whether this pipeline has been fitted to data.
public bool IsFitted { get; }
Property Value
Steps
Gets the named steps in the pipeline.
public IReadOnlyList<(string Name, IDataTransformer<T, TInput, TInput> Transformer)> Steps { get; }
Property Value
- IReadOnlyList<(string Name, IDataTransformer<T, TInput, TInput> Transformer)>
SupportsInverseTransform
Gets whether this pipeline supports inverse transformation.
public bool SupportsInverseTransform { get; }
Property Value
Remarks
A pipeline supports inverse transform if ALL its transformers support it.
Methods
Add(IDataTransformer<T, TInput, TInput>)
Adds a transformer step to the pipeline.
public PreprocessingPipeline<T, TInput, TOutput> Add(IDataTransformer<T, TInput, TInput> transformer)
Parameters
transformerIDataTransformer<T, TInput, TInput>The transformer to add.
Returns
- PreprocessingPipeline<T, TInput, TOutput>
This pipeline for method chaining.
Add(string, IDataTransformer<T, TInput, TInput>)
Adds a named transformer step to the pipeline.
public PreprocessingPipeline<T, TInput, TOutput> Add(string name, IDataTransformer<T, TInput, TInput> transformer)
Parameters
namestringThe name for this step.
transformerIDataTransformer<T, TInput, TInput>The transformer to add.
Returns
- PreprocessingPipeline<T, TInput, TOutput>
This pipeline for method chaining.
Clone()
Creates a clone of this pipeline without fitted state.
public PreprocessingPipeline<T, TInput, TOutput> Clone()
Returns
- PreprocessingPipeline<T, TInput, TOutput>
A new unfitted pipeline with the same structure.
Fit(TInput)
Fits all transformers in the pipeline to the training data.
public void Fit(TInput data)
Parameters
dataTInputThe training data to fit.
FitTransform(TInput)
Fits the pipeline and transforms the data in a single step.
public TOutput FitTransform(TInput data)
Parameters
dataTInputThe data to fit and transform.
Returns
- TOutput
The transformed data.
GetFeatureNamesOut(string[]?)
Gets the output feature names after all transformations.
public string[] GetFeatureNamesOut(string[]? inputFeatureNames = null)
Parameters
inputFeatureNamesstring[]The input feature names (optional).
Returns
- string[]
The output feature names.
GetStep(string)
Gets a transformer step by name.
public IDataTransformer<T, TInput, TInput>? GetStep(string name)
Parameters
namestringThe step name.
Returns
- IDataTransformer<T, TInput, TInput>
The transformer, or null if not found.
InverseTransform(TOutput)
Inverse transforms data through all pipeline steps in reverse order.
public TInput InverseTransform(TOutput data)
Parameters
dataTOutputThe transformed data.
Returns
- TInput
The original-scale data.
Exceptions
- NotSupportedException
Thrown if any step doesn't support inverse.
- InvalidOperationException
Thrown if not fitted.
SetFinalTransformer(IDataTransformer<T, TInput, TOutput>)
Sets the final transformer that may change the output type.
public PreprocessingPipeline<T, TInput, TOutput> SetFinalTransformer(IDataTransformer<T, TInput, TOutput> transformer)
Parameters
transformerIDataTransformer<T, TInput, TOutput>The final transformer.
Returns
- PreprocessingPipeline<T, TInput, TOutput>
This pipeline for method chaining.
Transform(TInput)
Transforms data through all pipeline steps.
public TOutput Transform(TInput data)
Parameters
dataTInputThe data to transform.
Returns
- TOutput
The transformed data.
Exceptions
- InvalidOperationException
Thrown if not fitted.