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.
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.
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
Notes
NaNs are treated as missing values: disregarded in fit, and maintained in
transform.
Compute the minimum and maximum to be used for later scaling.
Parameters:
X : array-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.
y : None
Ignored.
Returns:
self : object
Fitted scaler.
fit_transform(X, y=None, **fit_params)
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 of shape (n_samples, n_features)
Input samples.
y : array-like of shape (n_samples,) or (n_samples, n_outputs), default=None
Target values (None for unsupervised transformations).
**fit_params : dict
Additional fit parameters.
Pass only if the estimator accepts additional params in its fit method.
Returns:
X_new : ndarray array of shape (n_samples, n_features_new)
Transformed array.
get_feature_names_out(input_features=None)
Get output feature names for transformation.
Parameters:
input_features : array-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_out : ndarray of str objects
Same as input features.
get_metadata_routing()
Get metadata routing of this object.
Please check User Guide on how the routing
mechanism works.
If True, will return the parameters for this estimator and
contained subobjects that are estimators.
Returns:
params : dict
Parameter names mapped to their values.
inverse_transform(X)
Undo the scaling of X according to feature_range.
Parameters:
X : array-like of shape (n_samples, n_features)
Input data that will be transformed. It cannot be sparse.
Returns:
X_original : ndarray of shape (n_samples, n_features)
Transformed data.
partial_fit(X, y=None)
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 of
n_samples or because X is read from a continuous stream.
Parameters:
X : array-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.
The method works on simple estimators as well as on nested objects
(such as Pipeline). The latter have
parameters of the form <component>__<parameter> so that it’s
possible to update each component of a nested object.