RobustScaler#

class cuml.preprocessing.RobustScaler(*args, **kwargs)[source]#

Scale features using statistics that are robust to outliers.

This Scaler removes the median and scales the data according to the quantile range (defaults to IQR: Interquartile Range). The IQR is the range between the 1st quartile (25th quantile) and the 3rd quartile (75th quantile).

Centering and scaling happen independently on each feature by computing the relevant statistics on the samples in the training set. Median and interquartile range are then stored to be used on later data using the transform method.

Standardization of a dataset is a common requirement for many machine learning estimators. Typically this is done by removing the mean and scaling to unit variance. However, outliers can often influence the sample mean / variance in a negative way. In such cases, the median and the interquartile range often give better results.

Parameters:
with_centeringboolean, default=True

If True, center the data before scaling. This will cause transform to raise an exception when attempted on sparse matrices, because centering them entails building a dense matrix which in common use cases is likely to be too large to fit in memory.

with_scalingboolean, default=True

If True, scale the data to interquartile range.

quantile_rangetuple (q_min, q_max), 0.0 < q_min < q_max < 100.0

Default: (25.0, 75.0) = (1st quantile, 3rd quantile) = IQR Quantile range used to calculate scale_.

copyboolean, optional, default=True

Whether a forced copy will be triggered. If copy=False, a copy might be triggered by a conversion.

Attributes:
center_array of floats

The median value for each feature in the training set.

scale_array of floats

The (scaled) interquartile range for each feature in the training set.

Methods

fit(X[, y])

Compute the median and quantiles to be used for scaling.

inverse_transform(X)

Scale back the data to the original representation

transform(X)

Center and scale the data.

See also

robust_scale

Equivalent function without the estimator API.

cuml.decomposition.PCA

Further removes the linear correlation across features with whiten=True.

Examples

>>> from cuml.preprocessing import RobustScaler
>>> import cupy as cp
>>> X = [[ 1., -2.,  2.],
...      [ -2.,  1.,  3.],
...      [ 4.,  1., -2.]]
>>> X = cp.array(X)
>>> transformer = RobustScaler().fit(X)
>>> transformer
RobustScaler()
>>> transformer.transform(X)
array([[ 0. , -2. ,  0. ],
       [-1. ,  0. ,  0.4],
       [ 1. ,  0. , -1.6]])
fit(
X,
y=None,
) RobustScaler[source]#

Compute the median and quantiles to be used for scaling.

Parameters:
X{array-like, CSC matrix}, shape [n_samples, n_features]

The data used to compute the median and quantiles used for later scaling along the features axis.

fit_transform(X, y=None, **fit_params)[source]#

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

Parameters:
X{array-like, sparse matrix, dataframe} of shape (n_samples, n_features)
yndarray of shape (n_samples,), default=None

Target values.

**fit_paramsdict

Additional fit parameters.

Returns:
X_newndarray array of shape (n_samples, n_features_new)

Transformed array.

get_feature_names_out(input_features=None)[source]#

Get output feature names for transformation.

Parameters:
input_featuresarray-like of str or None, default=None

Input features.

  • If input_features is None, then feature_names_in_ is used as feature names in. If feature_names_in_ is not defined, then the following input feature names are generated: ["x0", "x1", ..., "x(n_features_in_ - 1)"].

  • If input_features is an array-like, then input_features must match feature_names_in_ if feature_names_in_ is defined.

Returns:
feature_names_outndarray of str objects

Same as input features.

get_params(deep=True)[source]#

Returns a dict of all params owned by this class. If the child class has appropriately overridden the _get_param_names method and does not need anything other than what is there in this method, then it doesn’t have to override this method

inverse_transform(X)[source]#

Scale back the data to the original representation

Parameters:
X{array-like, sparse matrix}

The data used to scale along the specified axis.

set_params(**params)[source]#

Accepts a dict of params and updates the corresponding ones owned by this class. If the child class has appropriately overridden the _get_param_names method and does not need anything other than what is, there in this method, then it doesn’t have to override this method

transform(X)[source]#

Center and scale the data.

Parameters:
X{array-like, sparse matrix}

The data used to scale along the specified axis.