-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
[MRG] DOC Clarify RobustScaler behavior with sparse input #8858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of small comments.
@@ -191,7 +191,7 @@ matrices as input, as long as ``with_mean=False`` is explicitly passed | |||
to the constructor. Otherwise a ``ValueError`` will be raised as | |||
silently centering would break the sparsity and would often crash the | |||
execution by allocating excessive amounts of memory unintentionally. | |||
:class:`RobustScaler` cannot be fited to sparse inputs, but you can use | |||
:class:`RobustScaler` cannot be fitted to sparse inputs, but you can use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah that was the typo, good catch
@@ -863,7 +863,7 @@ class RobustScaler(BaseEstimator, TransformerMixin): | |||
---------- | |||
with_centering : boolean, True by default | |||
If True, center the data before scaling. | |||
This does not work (and will raise an exception) when attempted on | |||
This will cause ``transform`` to raise an exception when attempted on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Edit: scratch this as well..fit
raises an exception if X
is sparse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, fit
on sparse raises regardless of any option. You can transform
on sparse after fit
ting on dense, apparently?
sklearn/preprocessing/data.py
Outdated
@@ -930,7 +930,8 @@ def _check_array(self, X, copy): | |||
return X | |||
|
|||
def fit(self, X, y=None): | |||
"""Compute the median and quantiles to be used for scaling. | |||
"""Compute the median and quantiles to be used for scaling. Note that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is only true if Edit: scratch that it will always raise an exception with with_centering=True
fit
.
I think because the docstring of the X
parameter does not mention that X
can be sparse we don't have to modify anything in the fit
docstring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also PEP257: first line of docstring should be standalone short description
Maybe we should update the docstring of |
Thanks for the input - reflected now |
Any other feedback @lesteve? |
ffe771f
to
4bcd5c6
Compare
4bcd5c6
to
8c50446
Compare
Rebased. |
"""Center and scale the data. | ||
|
||
Can be called on sparse input, provided that ``RobustScaler`` has been | ||
fitted to dense input and ``with_centering=False``. | ||
|
||
Parameters | ||
---------- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type description for X here site mention sparse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
8c50446
to
2ccf793
Compare
|
||
Parameters | ||
---------- | ||
X : array-like | ||
X : {array-like, sparse matrix} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jnothman if I read your feedback correctly, does this address the comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Sorry for the autocorrect typo.
Thanks |
Fixes #8796.