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
transformmethod.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
transformto 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.
Scale back the data to the original representation
transform(X)Center and scale the data.
See also
robust_scaleEquivalent function without the estimator API.
cuml.decomposition.PCAFurther 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.