Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4bcd5c6

Browse files
committed
Clarify RobustScaler behavior with sparse input
1 parent 689f412 commit 4bcd5c6

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

doc/modules/preprocessing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ matrices as input, as long as ``with_mean=False`` is explicitly passed
199199
to the constructor. Otherwise a ``ValueError`` will be raised as
200200
silently centering would break the sparsity and would often crash the
201201
execution by allocating excessive amounts of memory unintentionally.
202-
:class:`RobustScaler` cannot be fited to sparse inputs, but you can use
202+
:class:`RobustScaler` cannot be fitted to sparse inputs, but you can use
203203
the ``transform`` method on sparse inputs.
204204

205205
Note that the scalers accept both Compressed Sparse Rows and Compressed

sklearn/preprocessing/data.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -885,9 +885,9 @@ class RobustScaler(BaseEstimator, TransformerMixin):
885885
and the 3rd quartile (75th quantile).
886886
887887
Centering and scaling happen independently on each feature (or each
888-
sample, depending on the `axis` argument) by computing the relevant
888+
sample, depending on the ``axis`` argument) by computing the relevant
889889
statistics on the samples in the training set. Median and interquartile
890-
range are then stored to be used on later data using the `transform`
890+
range are then stored to be used on later data using the ``transform``
891891
method.
892892
893893
Standardization of a dataset is a common requirement for many
@@ -904,7 +904,7 @@ class RobustScaler(BaseEstimator, TransformerMixin):
904904
----------
905905
with_centering : boolean, True by default
906906
If True, center the data before scaling.
907-
This does not work (and will raise an exception) when attempted on
907+
This will cause ``transform`` to raise an exception when attempted on
908908
sparse matrices, because centering them entails building a dense
909909
matrix which in common use cases is likely to be too large to fit in
910910
memory.
@@ -999,7 +999,10 @@ def fit(self, X, y=None):
999999
return self
10001000

10011001
def transform(self, X, y=None):
1002-
"""Center and scale the data
1002+
"""Center and scale the data.
1003+
1004+
Can be called on sparse input, provided that ``RobustScaler`` has been
1005+
fitted to dense input and ``with_centering=False``.
10031006
10041007
Parameters
10051008
----------

0 commit comments

Comments
 (0)