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.
| 303 | |
| 304 | |
| 305 | class MinMaxScaler(OneToOneFeatureMixin, TransformerMixin, BaseEstimator): |
| 306 | """Transform features by scaling each feature to a given range. |
| 307 | |
| 308 | This estimator scales and translates each feature individually such |
| 309 | that it is in the given range on the training set, e.g. between |
| 310 | zero and one. |
| 311 | |
| 312 | The transformation is given by:: |
| 313 | |
| 314 | X_std = (X - X.min(axis=0)) / (X.max(axis=0) - X.min(axis=0)) |
| 315 | X_scaled = X_std * (max - min) + min |
| 316 | |
| 317 | where min, max = feature_range. |
| 318 | |
| 319 | This transformation is often used as an alternative to zero mean, |
| 320 | unit variance scaling. |
| 321 | |
| 322 | `MinMaxScaler` doesn't reduce the effect of outliers, but it linearly |
| 323 | scales them down into a fixed range, where the largest occurring data point |
| 324 | corresponds to the maximum value and the smallest one corresponds to the |
| 325 | minimum value. For an example visualization, refer to :ref:`Compare |
| 326 | MinMaxScaler with other scalers <plot_all_scaling_minmax_scaler_section>`. |
| 327 | |
| 328 | Read more in the :ref:`User Guide <preprocessing_scaler>`. |
| 329 | |
| 330 | Parameters |
| 331 | ---------- |
| 332 | feature_range : tuple (min, max), default=(0, 1) |
| 333 | Desired range of transformed data. |
| 334 | |
| 335 | copy : bool, default=True |
| 336 | Set to False to perform inplace row normalization and avoid a |
| 337 | copy (if the input is already a numpy array). |
| 338 | |
| 339 | clip : bool, default=False |
| 340 | Set to True to clip transformed values of held-out data to |
| 341 | provided `feature_range`. |
| 342 | Since this parameter will clip values, `inverse_transform` may not |
| 343 | be able to restore the original data. |
| 344 | |
| 345 | .. note:: |
| 346 | Setting `clip=True` does not prevent feature drift (a distribution |
| 347 | shift between training and test data). The transformed values are clipped |
| 348 | to the `feature_range`, which helps avoid unintended behavior in models |
| 349 | sensitive to out-of-range inputs (e.g. linear models). Use with care, |
| 350 | as clipping can distort the distribution of test data. |
| 351 | |
| 352 | .. versionadded:: 0.24 |
| 353 | |
| 354 | Attributes |
| 355 | ---------- |
| 356 | min_ : ndarray of shape (n_features,) |
| 357 | Per feature adjustment for minimum. Equivalent to |
| 358 | ``min - X.min(axis=0) * self.scale_`` |
| 359 | |
| 360 | scale_ : ndarray of shape (n_features,) |
| 361 | Per feature relative scaling of the data. Equivalent to |
| 362 | ``(max - min) / (X.max(axis=0) - X.min(axis=0))`` |
no outgoing calls
searching dependent graphs…