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

Skip to content

Commit 2ccf793

Browse files
committed
Clarify RobustScaler behavior with sparse input
1 parent b6f8865 commit 2ccf793

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
@@ -909,9 +909,9 @@ class RobustScaler(BaseEstimator, TransformerMixin):
909909
and the 3rd quartile (75th quantile).
910910
911911
Centering and scaling happen independently on each feature (or each
912-
sample, depending on the `axis` argument) by computing the relevant
912+
sample, depending on the ``axis`` argument) by computing the relevant
913913
statistics on the samples in the training set. Median and interquartile
914-
range are then stored to be used on later data using the `transform`
914+
range are then stored to be used on later data using the ``transform``
915915
method.
916916
917917
Standardization of a dataset is a common requirement for many
@@ -928,7 +928,7 @@ class RobustScaler(BaseEstimator, TransformerMixin):
928928
----------
929929
with_centering : boolean, True by default
930930
If True, center the data before scaling.
931-
This does not work (and will raise an exception) when attempted on
931+
This will cause ``transform`` to raise an exception when attempted on
932932
sparse matrices, because centering them entails building a dense
933933
matrix which in common use cases is likely to be too large to fit in
934934
memory.
@@ -1023,11 +1023,14 @@ def fit(self, X, y=None):
10231023
return self
10241024

10251025
def transform(self, X):
1026-
"""Center and scale the data
1026+
"""Center and scale the data.
1027+
1028+
Can be called on sparse input, provided that ``RobustScaler`` has been
1029+
fitted to dense input and ``with_centering=False``.
10271030
10281031
Parameters
10291032
----------
1030-
X : array-like
1033+
X : {array-like, sparse matrix}
10311034
The data used to scale along the specified axis.
10321035
"""
10331036
if self.with_centering:

0 commit comments

Comments
 (0)