Table of Contents

Interface IDataTransformer<T, TInput, TOutput>

Namespace
AiDotNet.Interfaces
Assembly
AiDotNet.dll

Defines a data transformer that can fit to data and transform it.

public interface IDataTransformer<T, TInput, TOutput>

Type Parameters

T

The numeric type for calculations (e.g., float, double).

TInput

The input data type.

TOutput

The output data type after transformation.

Remarks

This is the core interface for all preprocessing transformers in AiDotNet. It follows the sklearn-style Fit/Transform pattern where transformers first learn parameters from training data (Fit), then apply transformations (Transform).

For Beginners: A transformer is like a recipe that: 1. First "learns" from your training data (e.g., calculates mean and std for scaling) 2. Then applies the same recipe to any new data

This ensures new data is processed exactly the same way as training data.

Properties

ColumnIndices

Gets the column indices this transformer operates on.

int[]? ColumnIndices { get; }

Property Value

int[]

Remarks

If null or empty, the transformer operates on all columns. Otherwise, it only processes the specified column indices.

For Beginners: Some transformers only apply to certain columns. For example, OneHotEncoder might only encode columns 2 and 5. If this is null, the transformer applies to all columns.

IsFitted

Gets whether this transformer has been fitted to data.

bool IsFitted { get; }

Property Value

bool

Remarks

Returns true after Fit(TInput) or FitTransform(TInput) has been called. Transform operations require the transformer to be fitted first.

For Beginners: This tells you if the transformer has "learned" from training data yet. You must call Fit() before Transform().

SupportsInverseTransform

Gets whether this transformer supports inverse transformation.

bool SupportsInverseTransform { get; }

Property Value

bool

Remarks

Some transformers can reverse their transformation (e.g., StandardScaler can convert scaled values back to original scale). Others cannot (e.g., OneHotEncoder may lose information about category ordering).

For Beginners: If this is true, you can "undo" the transformation. This is useful for converting predictions back to the original scale.

Methods

Fit(TInput)

Fits the transformer to the training data, learning any parameters needed for transformation.

void Fit(TInput data)

Parameters

data TInput

The training data to fit.

Remarks

This method learns transformation parameters from the data. For example: - StandardScaler learns mean and standard deviation - MinMaxScaler learns min and max values - OneHotEncoder learns unique categories

For Beginners: Call this once on your training data. The transformer will remember what it learned and use it for all future transforms.

FitTransform(TInput)

Fits the transformer and transforms the data in a single step.

TOutput FitTransform(TInput data)

Parameters

data TInput

The data to fit and transform.

Returns

TOutput

The transformed data.

Remarks

This is a convenience method that combines Fit and Transform. Use this for training data where you want to fit and transform in one call.

For Beginners: Use this for your training data. It's equivalent to calling Fit() then Transform(), but more convenient.

GetFeatureNamesOut(string[]?)

Gets the output feature names after transformation.

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

Parameters

inputFeatureNames string[]

The input feature names (optional).

Returns

string[]

The output feature names.

Remarks

Returns meaningful names for the output features. For transformers that change the number of features (like OneHotEncoder or PolynomialFeatures), this returns names reflecting the new features.

For Beginners: This helps you understand what each column means after transformation. For example, after OneHotEncoder, you get names like "color_red", "color_blue" instead of just column numbers.

InverseTransform(TOutput)

Reverses the transformation (if supported).

TInput InverseTransform(TOutput data)

Parameters

data TOutput

The transformed data.

Returns

TInput

The original-scale data.

Remarks

Converts transformed data back to its original scale. This is useful for interpreting predictions that were made on scaled data.

For Beginners: If you scaled your target values before training, use this to convert predictions back to the original scale (like dollars or temperatures).

Exceptions

NotSupportedException

Thrown if inverse transform is not supported.

InvalidOperationException

Thrown if Fit() has not been called.

Transform(TInput)

Transforms the input data using the fitted parameters.

TOutput Transform(TInput data)

Parameters

data TInput

The data to transform.

Returns

TOutput

The transformed data.

Remarks

Applies the learned transformation to the data. This method can be called multiple times with different data after fitting.

For Beginners: Use this to transform your test data or new predictions. It applies the same transformation that was learned from training data.

Exceptions

InvalidOperationException

Thrown if Fit() has not been called.