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

Skip to content

Commit f6c7080

Browse files
naoyakjnothman
authored andcommitted
DOC Clarify RobustScaler behavior with sparse input (#8858)
1 parent 30a7ce9 commit f6c7080

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
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: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -945,9 +945,9 @@ class RobustScaler(BaseEstimator, TransformerMixin):
945945
and the 3rd quartile (75th quantile).
946946
947947
Centering and scaling happen independently on each feature (or each
948-
sample, depending on the `axis` argument) by computing the relevant
948+
sample, depending on the ``axis`` argument) by computing the relevant
949949
statistics on the samples in the training set. Median and interquartile
950-
range are then stored to be used on later data using the `transform`
950+
range are then stored to be used on later data using the ``transform``
951951
method.
952952
953953
Standardization of a dataset is a common requirement for many
@@ -964,7 +964,7 @@ class RobustScaler(BaseEstimator, TransformerMixin):
964964
----------
965965
with_centering : boolean, True by default
966966
If True, center the data before scaling.
967-
This does not work (and will raise an exception) when attempted on
967+
This will cause ``transform`` to raise an exception when attempted on
968968
sparse matrices, because centering them entails building a dense
969969
matrix which in common use cases is likely to be too large to fit in
970970
memory.
@@ -1059,11 +1059,14 @@ def fit(self, X, y=None):
10591059
return self
10601060

10611061
def transform(self, X):
1062-
"""Center and scale the data
1062+
"""Center and scale the data.
1063+
1064+
Can be called on sparse input, provided that ``RobustScaler`` has been
1065+
fitted to dense input and ``with_centering=False``.
10631066
10641067
Parameters
10651068
----------
1066-
X : array-like
1069+
X : {array-like, sparse matrix}
10671070
The data used to scale along the specified axis.
10681071
"""
10691072
if self.with_centering:

0 commit comments

Comments
 (0)