MinMaxScaler#
- class cuml.preprocessing.MinMaxScaler(*args, **kwargs)[source]#
Transform features by scaling each feature to a given range.
This estimator scales and translates each feature individually such that it is in the given range on the training set, e.g. between zero and one.
The transformation is given by:
X_std = (X - X.min(axis=0)) / (X.max(axis=0) - X.min(axis=0)) X_scaled = X_std * (max - min) + min
where min, max = feature_range.
This transformation is often used as an alternative to zero mean, unit variance scaling.
- Parameters:
- feature_rangetuple (min, max), default=(0, 1)
Desired range of transformed data.
- copybool, default=True
Whether a forced copy will be triggered. If copy=False, a copy might be triggered by a conversion.
- Attributes:
- min_ndarray of shape (n_features,)
Per feature adjustment for minimum. Equivalent to
min - X.min(axis=0) * self.scale_- scale_ndarray of shape (n_features,)
Per feature relative scaling of the data. Equivalent to
(max - min) / (X.max(axis=0) - X.min(axis=0))- data_min_ndarray of shape (n_features,)
Per feature minimum seen in the data
- data_max_ndarray of shape (n_features,)
Per feature maximum seen in the data
- data_range_ndarray of shape (n_features,)
Per feature range
(data_max_ - data_min_)seen in the data- n_samples_seen_int
The number of samples processed by the estimator. It will be reset on new calls to fit, but increments across
partial_fitcalls.
Methods
fit(X[, y])Compute the minimum and maximum to be used for later scaling.
Undo the scaling of X according to feature_range.
partial_fit(X[, y])Online computation of min and max on X for later scaling.
transform(X)Scale features of X according to feature_range.
See also
minmax_scaleEquivalent function without the estimator API.
Notes
NaNs are treated as missing values: disregarded in fit, and maintained in transform.
Examples
>>> from cuml.preprocessing import MinMaxScaler >>> import cupy as cp >>> data = [[-1, 2], [-0.5, 6], [0, 10], [1, 18]] >>> data = cp.array(data) >>> scaler = MinMaxScaler() >>> print(scaler.fit(data)) MinMaxScaler() >>> print(scaler.data_max_) [ 1. 18.] >>> print(scaler.transform(data)) [[0. 0. ] [0.25 0.25] [0.5 0.5 ] [1. 1. ]] >>> print(scaler.transform(cp.array([[2, 2]]))) [[1.5 0. ]]
- fit(X, y=None) MinMaxScaler[source]#
Compute the minimum and maximum to be used for later scaling.
- Parameters:
- Xarray-like of shape (n_samples, n_features)
The data used to compute the per-feature minimum and maximum used for later scaling along the features axis.
- yNone
Ignored.
- Returns:
- selfobject
Fitted scaler.
- inverse_transform(X) CumlArray[source]#
Undo the scaling of X according to feature_range.
- Parameters:
- Xarray-like of shape (n_samples, n_features)
Input data that will be transformed. It cannot be sparse.
- Returns:
- Xtarray-like of shape (n_samples, n_features)
Transformed data.
- partial_fit(X, y=None) MinMaxScaler[source]#
Online computation of min and max on X for later scaling.
All of X is processed as a single batch. This is intended for cases when
fit()is not feasible due to very large number ofn_samplesor because X is read from a continuous stream.- Parameters:
- Xarray-like of shape (n_samples, n_features)
The data used to compute the mean and standard deviation used for later scaling along the features axis.
- yNone
Ignored.
- Returns:
- selfobject
Transformer instance.