-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
DOC Improve docstring around set_output #24672
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
sklearn/pipeline.py
Outdated
@@ -158,6 +158,10 @@ def set_output(self, transform=None): | |||
transform : {"default", "pandas"}, default=None | |||
Configure output of `transform` and `fit_transform`. | |||
|
|||
- `"default"`: Output of an un-configured transformer | |||
- `"pandas"`: DataFrames output | |||
- `"None"`: No-op |
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.
Uhm. It should be the keyword None
and not the string "None"
, isn't it?
@@ -265,6 +265,10 @@ def set_output(self, transform=None): | |||
transform : {"default", "pandas"}, default=None | |||
Configure output of `transform` and `fit_transform`. | |||
|
|||
- `"default"`: Output of an un-configured transformer | |||
- `"pandas"`: DataFrames output | |||
- `"None"`: No-op |
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.
After reading the "no op" explanation I was left wondering how "no-op" was different from "default". Looking at the code I think the answer is "they are the same". If that is correct, can we say "None
: Default output (format) of a transformer"?
I think I like "Default output format of a transformer" better than "Output of an un-configured transformer", but I am not sure if they are equivalent? As in, I could imagine that there is a subtle difference between "unconfigured" and "default"?,
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 no-op
is supposed to mean transform=None
would do nothing, but transform="default"
sets the output to be pandas
. As in: est.set_output(transform="pandas").set_outout(transform=None)
vs est.set_output(transform="pandas").set_outout(transform="default")
: the first one returns a pandas dataframe.
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.
Ouf, that is subtle indeed. Why does None
exist as an option if it does nothing (not even reset the state to "unconfigured")?
but
transform="default"
sets the output to bepandas
is this right? I was expecting "default"
to be "not pandas"/numpy because there is an option to set pandas
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.
is this right?
Sorry, typo, but you got the intention :D
Why does None exist as an option if it does nothing
This method might start having other args as well, and then we'd want to be able to set only one thing, while leaving the rest unchanged:
def f(a=None, b=None):
...
# This would not change the value set by the method for `b`
f(a="value")
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.
Why does None exist as an option if it does nothing (not even reset the state to "unconfigured")?
In the future, we may want to add predict
to set_output
:
pipe.set_output(transform="pandas")
pipe.set_output(predict="pandas")
The second call with predict="pandas"
should not adjust the configuration for transform
.
is this right? I was expecting "default" to be "not pandas"/numpy because there is an option to set pandas
I took into account existing third party estimators that only return DataFrames as the default. If we had "default" == "numpy" output, then they would not be following the set_output
API. I did not want to add more work for third party libraries to convert their DataFrames into NumPy arrays just to conform to the API.
Even in scikit-learn, there are three possible return containers for transform="default"
:
- With the recent Array API support: Any Array API container such as
cupy.array_api.Array
- NumPy's ndarray
- SciPy's 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.
From this discussion, I updated the docstring to:
- `"default"`: Default output format of a transformer
- `"pandas"`: DataFrame output
- `None`: Transform configuration is unchanged
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.
Cool! Thanks for all the explanations. I like your change Thomas.
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.
LGTM
* DOC Improve docstring around set_output * DOC Improve docs around set_output * DOC Address comments * DOC Better grammar * DOC Improve wording * DOC Improves docstring in set_config
Reference Issues/PRs
Related to scikit-learn/enhancement_proposals#78
What does this implement/fix? Explain your changes.
This PR improves the user docs and developer docs around
set_output
.