Class PowerTransformer<T>
- Namespace
- AiDotNet.Preprocessing.PowerTransforms
- Assembly
- AiDotNet.dll
Applies power transformations (Box-Cox or Yeo-Johnson) to make data more Gaussian-like.
public class PowerTransformer<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
-
PowerTransformer<T>
- Implements
- Inherited Members
Remarks
PowerTransformer applies a power transformation to each feature to make it more Gaussian-like. Box-Cox requires strictly positive data, while Yeo-Johnson works with any values. The transformation can help stabilize variance and improve the fit of models that assume normality.
For Beginners: This transformer makes your data more "bell-curve shaped": - Box-Cox: For strictly positive data (prices, counts) - Yeo-Johnson: Works with any data including negatives and zeros
After transformation, features will have more normal (Gaussian) distributions, which helps many machine learning algorithms perform better.
Constructors
PowerTransformer(PowerTransformMethod, bool, int[]?)
Creates a new instance of PowerTransformer<T>.
public PowerTransformer(PowerTransformMethod method = PowerTransformMethod.YeoJohnson, bool standardize = true, int[]? columnIndices = null)
Parameters
methodPowerTransformMethodThe transformation method. Defaults to YeoJohnson.
standardizeboolWhether to standardize after transformation. Defaults to true.
columnIndicesint[]The column indices to transform, or null for all columns.
Properties
Lambdas
Gets the optimal lambda parameters for each feature.
public Vector<T>? Lambdas { get; }
Property Value
- Vector<T>
Method
Gets the power transformation method used.
public PowerTransformMethod Method { get; }
Property Value
Standardize
Gets whether standardization is applied after transformation.
public bool Standardize { get; }
Property Value
SupportsInverseTransform
Gets whether this transformer supports inverse transformation.
public override bool SupportsInverseTransform { get; }
Property Value
Methods
FitCore(Matrix<T>)
Learns the optimal lambda parameters for each feature.
protected override void FitCore(Matrix<T> data)
Parameters
dataMatrix<T>The training data matrix where each column is a feature.
GetFeatureNamesOut(string[]?)
Gets the output feature names after transformation.
public override string[] GetFeatureNamesOut(string[]? inputFeatureNames = null)
Parameters
inputFeatureNamesstring[]The input feature names.
Returns
- string[]
The same feature names (PowerTransformer doesn't change number of features).
InverseTransformCore(Matrix<T>)
Reverses the power transformation.
protected override Matrix<T> InverseTransformCore(Matrix<T> data)
Parameters
dataMatrix<T>The transformed data.
Returns
- Matrix<T>
The original-scale data.
TransformCore(Matrix<T>)
Transforms the data by applying the power transformation.
protected override Matrix<T> TransformCore(Matrix<T> data)
Parameters
dataMatrix<T>The data to transform.
Returns
- Matrix<T>
The transformed data.