DOC add warning note regarding data leakage by using scale and robust_scale
@@ -137,6 +137,18 @@ def scale(X, *, axis=0, with_mean=True, with_std=True, copy=True):
see :ref:`examples/preprocessing/plot_all_scaling.py
<sphx_glr_auto_examples_preprocessing_plot_all_scaling.py>`.
+ .. warning:: Risk of data leak
+
+ Do not use :func:`~sklearn.preprocessing.scale` unless you know
+ what you are doing. A common mistake is to apply it to the entire data
+ *before* splitting into training and test sets. This will bias the
+ model evaluation because information would have leaked from the test
+ set to the training set.
+ In general, we recommend using
+ :class:`~sklearn.preprocessing.StandardScaler` within a
+ :ref:`Pipeline <pipeline>` in order to prevent most risks of data
+ leaking: `pipe = make_pipeline(StandardScaler(), LogisticRegression())`.
+
See also
--------
StandardScaler: Performs scaling to unit variance using the``Transformer`` API
@@ -1455,6 +1467,18 @@ def robust_scale(X, *, axis=0, with_centering=True, with_scaling=True,
see :ref:`examples/preprocessing/plot_all_scaling.py
<sphx_glr_auto_examples_preprocessing_plot_all_scaling.py>`.
+ .. warning:: Risk of data leak
+
+ Do not use :func:`~sklearn.preprocessing.robust_scale` unless you know
+ what you are doing. A common mistake is to apply it to the entire data
+ *before* splitting into training and test sets. This will bias the
+ model evaluation because information would have leaked from the test
+ set to the training set.
+ In general, we recommend using
+ :class:`~sklearn.preprocessing.RobustScaler` within a
+ :ref:`Pipeline <pipeline>` in order to prevent most risks of data
+ leaking: `pipe = make_pipeline(RobustScaler(), LogisticRegression())`.
+
See also
--------
RobustScaler: Performs centering and scaling using the ``Transformer`` API
