MaxAbsScaler
#include <Skigen/Preprocessing>
template <typename Scalar = double>
class Skigen::MaxAbsScaler(clip=false)
Scale each feature by its maximum absolute value.
This estimator scales and translates each feature individually such that the maximal absolute value of each feature in the training set will be 1.0. It does not shift/center the data, and thus does not destroy any sparsity.
Mirrors sklearn.preprocessing.MaxAbsScaler.
Parameters:
- clip : bool, default=false
Whether to clip transformed values to
[-1, 1](bool, defaultfalse).
Attributes:
-
clip : bool Whether clipping is enabled.
-
max_abs : RowVectorType Per-feature maximum absolute value (1 × n_features).
-
scale : RowVectorType Per-feature scaling factor (1 × n_features).
-
n_samples_seen : IndexType Number of samples processed during
fit().
Methods
fit(X)
Compute per-feature maximum absolute value for later scaling.
Parameters:
- X : MatrixType Training data of shape (n_samples, n_features).
Returns:
- result : MaxAbsScaler
Reference to the fitted transformer (
*this).
transform(X)
Scale features of X by max absolute value.
Parameters:
- X : MatrixType Data matrix of shape (n_samples, n_features).
Returns:
- result : MatrixType
Transformed data of same shape, scaled to
[-1, 1].
Throws:
std::runtime_error— if the model has not been fitted.
inverse_transform(X)
Scale back the data to the original representation.
Parameters:
- X : MatrixType Transformed data of shape (n_samples, n_features).
Returns:
- result : MatrixType Un-transformed data of same shape.
Throws:
std::runtime_error— if the model has not been fitted.
transform_inplace(X)
Transform features in-place by scaling by max absolute value.
Parameters:
- X : Eigen::Ref< MatrixType > Data matrix of shape (n_samples, n_features), modified in place.
Throws:
std::runtime_error— if the model has not been fitted.
inverse_transform_inplace(X)
Inverse-transform features in-place to original scale.
Parameters:
- X : Eigen::Ref< MatrixType > Scaled data matrix, modified in place.
Throws:
std::runtime_error— if the model has not been fitted.
Example
Skigen::MaxAbsScaler<double> scaler;
Eigen::MatrixXd Z = scaler.fit_transform(X);
std::cout << "MaxAbs scaled (range [-1, 1]):\n" << Z << "\n\n";
std::cout << "Max absolute values: " << scaler.max_abs() << "\n";
std::cout << "Scale factors: " << scaler.scale() << "\n\n";
// Round-trip
Eigen::MatrixXd X_back = scaler.inverse_transform(Z);
std::cout << "Recovered:\n" << X_back << "\n";