MinMaxScaler#
- class caf.cvt.layering.MinMaxScaler(feature_range=(0, 1), *, copy=True, clip=False)#
Bases:
OneToOneFeatureMixin,TransformerMixin,BaseEstimatorTransform 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.
MinMaxScaler doesn’t reduce the effect of outliers, but it linearly scales them down into a fixed range, where the largest occurring data point corresponds to the maximum value and the smallest one corresponds to the minimum value. For an example visualization, refer to Compare MinMaxScaler with other scalers.
Read more in the User Guide.
- Parameters:
feature_range (tuple (min, max), default=(0, 1)) – Desired range of transformed data.
copy (bool, default=True) – Set to False to perform inplace row normalization and avoid a copy (if the input is already a numpy array).
clip (bool, default=False) –
Set to True to clip transformed values of held-out data to provided feature_range. Since this parameter will clip values, inverse_transform may not be able to restore the original data.
Note
Setting clip=True does not prevent feature drift (a distribution shift between training and test data). The transformed values are clipped to the feature_range, which helps avoid unintended behavior in models sensitive to out-of-range inputs (e.g. linear models). Use with care, as clipping can distort the distribution of test data.
Added in version 0.24.
- min_#
Per feature adjustment for minimum. Equivalent to
min - X.min(axis=0) * self.scale_- Type:
ndarray of shape (n_features,)
- scale_#
Per feature relative scaling of the data. Equivalent to
(max - min) / (X.max(axis=0) - X.min(axis=0))Added in version 0.17: scale_ attribute.
- Type:
ndarray of shape (n_features,)
- data_min_#
Per feature minimum seen in the data
Added in version 0.17: data_min_
- Type:
ndarray of shape (n_features,)
- data_max_#
Per feature maximum seen in the data
Added in version 0.17: data_max_
- Type:
ndarray of shape (n_features,)
- data_range_#
Per feature range
(data_max_ - data_min_)seen in the dataAdded in version 0.17: data_range_
- Type:
ndarray of shape (n_features,)
- n_samples_seen_#
The number of samples processed by the estimator. It will be reset on new calls to fit, but increments across
partial_fitcalls.- Type:
- feature_names_in_#
Names of features seen during fit. Defined only when X has feature names that are all strings.
Added in version 1.0.
- Type:
ndarray of shape (n_features_in_,)
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 sklearn.preprocessing import MinMaxScaler >>> data = [[-1, 2], [-0.5, 6], [0, 10], [1, 18]] >>> 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([[2, 2]])) [[1.5 0. ]]
Methods
__init__([feature_range, copy, clip])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.