MLZScoreScaler: Z-Score Scaler

MLZScoreScalerR Documentation

Z-Score Scaler

Description

Standardizes features by removing the mean and scaling to unit variance (Bessel-corrected, n - 1). The center/scale arguments follow R's scale(): with center = FALSE, scale = TRUE columns are divided by the root-mean-square around 0.

Details

The *_inplace methods mutate X directly (zero-copy) when it is a double-storage matrix; other inputs are coerced to a double matrix first, in which case the coerced copy is modified. The (modified) matrix is returned in both cases. X may also be an mmap_matrix created by mem_matrix / mem_matrix_from: the disk-backed buffer is then bound zero-copy through the same Eigen map interface and modified in place on disk. All scaler methods — including fit() — require the handle to be open in "readwrite" mode, because the scaler core binds a mutable map.

Methods

Public methods


MLZScoreScaler$new()

Initialize the MLZScoreScaler

Usage
MLZScoreScaler$new(center = TRUE, scale = TRUE, n_threads = NULL)
Arguments
center

Logical, whether to center columns to mean 0 (default: TRUE)

scale

Logical, whether to scale columns to unit SD (default: TRUE); around 0 instead of the mean when center = FALSE, as in R's scale().

n_threads

Integer, the thread budget of the column passes (NULL, the default: the library's default budget, trex_get_num_threads(), initially 1).


MLZScoreScaler$fit()

Compute the centers and scales to be used for later scaling.

Usage
MLZScoreScaler$fit(X, threshold = 1e-12)
Arguments
X

A numeric matrix (n x p) or an mmap_matrix in "readwrite" mode (the scaler core binds a mutable map).

threshold

Double, lower bound for the scale statistic (default: 1e-12).

Returns

Value.


MLZScoreScaler$transform_inplace()

Perform standardization by centering and scaling in-place.

Usage
MLZScoreScaler$transform_inplace(X)
Arguments
X

A numeric matrix (n x p) or an mmap_matrix in "readwrite" mode.

Returns

The modified matrix X (the same handle for an mmap_matrix).


MLZScoreScaler$inverse_transform_inplace()

Inverse transform to original scale.

Usage
MLZScoreScaler$inverse_transform_inplace(X)
Arguments
X

A numeric matrix (n x p) or an mmap_matrix in "readwrite" mode.

Returns

The modified matrix X (the same handle for an mmap_matrix).


MLZScoreScaler$fit_transform_inplace()

Fit and transform in one call, like R's scale().

Usage
MLZScoreScaler$fit_transform_inplace(X, threshold = 1e-12)
Arguments
X

A numeric matrix (n x p) or an mmap_matrix in "readwrite" mode.

threshold

Double, lower bound for the scale statistic (default: 1e-12).

Returns

The modified matrix X (the same handle for an mmap_matrix).


MLZScoreScaler$is_fitted()

Check if scaler is fitted.

Usage
MLZScoreScaler$is_fitted()
Returns

Value.


MLZScoreScaler$get_dropped_indices()

Get dropped (degenerate) column indices. These columns get scale factor 1 and are still centered (sklearn semantics).

Usage
MLZScoreScaler$get_dropped_indices()
Returns

Value.


MLZScoreScaler$get_center()

Check if scaler centers data.

Usage
MLZScoreScaler$get_center()
Returns

Value.


MLZScoreScaler$get_scale()

Check if scaler scales data to unit variance.

Usage
MLZScoreScaler$get_scale()
Returns

Value.


MLZScoreScaler$get_centers()

Get the learned centers (column means).

Usage
MLZScoreScaler$get_centers()
Returns

Value.


MLZScoreScaler$get_scales()

Get the learned scales (standard deviations).

Usage
MLZScoreScaler$get_scales()
Returns

Value.


MLZScoreScaler$save()

Save model state to file.

Usage
MLZScoreScaler$save(filename)
Arguments
filename

String path to save output.

Returns

Value.


MLZScoreScaler$load()

Load model state from file.

Usage
MLZScoreScaler$load(filename)
Arguments
filename

String path to load input from.

Returns

Value.


MLZScoreScaler$clone()

The objects of this class are cloneable with this method.

Usage
MLZScoreScaler$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

Other ML methods: MLElasticNet, MLElasticNetCV, MLLpNormScaler, MLPCA, MLRidge, MLRidgeCV, MLSVD, ml_agglomerative_cluster(), ml_cut_tree(), ml_distance_metric, ml_linkage_method

Examples

set.seed(1)
X <- matrix(rnorm(50 * 5), 50, 5)
scaler <- MLZScoreScaler$new()
scaler$fit(X)
X_std <- scaler$transform_inplace(X)
scaler$get_centers()


TRexSelector documentation built on Nov. 20, 2026, 5:09 p.m.