Class LogMeanVarianceScaler<T>
- Namespace
- AiDotNet.Preprocessing.Scalers
- Assembly
- AiDotNet.dll
Applies logarithmic transformation followed by mean-variance standardization.
public class LogMeanVarianceScaler<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
-
LogMeanVarianceScaler<T>
- Implements
- Inherited Members
Remarks
Log-mean-variance scaling combines logarithmic transformation with z-score standardization. It first applies log transformation (with shift for negative values), then standardizes using mean and standard deviation. This is ideal for data spanning multiple orders of magnitude.
For Beginners: This scaler is perfect for highly skewed or exponentially distributed data: - First, it takes the log of values (compressing large differences) - Then, it standardizes to zero mean and unit variance
Example: [1000, 10000, 100000, 1000000] → after log: [6.9, 9.2, 11.5, 13.8] → standardized This makes patterns in exponential data much easier to detect.
Constructors
LogMeanVarianceScaler(int[]?)
Creates a new instance of LogMeanVarianceScaler<T>.
public LogMeanVarianceScaler(int[]? columnIndices = null)
Parameters
columnIndicesint[]The column indices to scale, or null for all columns.
Properties
LogMean
Gets the mean of log-transformed values for each feature.
public Vector<T>? LogMean { get; }
Property Value
- Vector<T>
LogStdDev
Gets the standard deviation of log-transformed values for each feature.
public Vector<T>? LogStdDev { get; }
Property Value
- Vector<T>
Shift
Gets the shift applied to each feature to ensure positive values.
public Vector<T>? Shift { get; }
Property Value
- Vector<T>
SupportsInverseTransform
Gets whether this transformer supports inverse transformation.
public override bool SupportsInverseTransform { get; }
Property Value
Methods
FitCore(Matrix<T>)
Computes the shift, log mean, and log standard deviation 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 (LogMeanVarianceScaler doesn't change number of features).
InverseTransformCore(Matrix<T>)
Reverses the log-mean-variance scaling transformation.
protected override Matrix<T> InverseTransformCore(Matrix<T> data)
Parameters
dataMatrix<T>The scaled data.
Returns
- Matrix<T>
The original-scale data.
TransformCore(Matrix<T>)
Transforms the data by applying log transformation and standardization.
protected override Matrix<T> TransformCore(Matrix<T> data)
Parameters
dataMatrix<T>The data to transform.
Returns
- Matrix<T>
The log-standardized data.