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

Skip to content

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

Merged
merged 6 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/developers/develop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,9 @@ setting `auto_wrap_output_keys=None` when defining a custom subclass::
def get_feature_names_out(self, input_features=None):
...

The default value for `auto_wrap_output_keys` is `("transform",)`, which automatically
wraps `fit_transform` and `transform`.

For transformers that return multiple arrays in `transform`, auto wrapping will
only wrap the first array and not alter the other arrays.

Expand Down
18 changes: 16 additions & 2 deletions sklearn/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,14 @@ def set_config(
.. versionadded:: 1.2

transform_output : str, default=None
Configure the output container for transform.
Configure output of `transform` and `fit_transform`.

See :ref:`sphx_glr_auto_examples_miscellaneous_plot_set_output.py`
for an example on how to use the API.

- `"default"`: Default output format of a transformer
- `"pandas"`: DataFrame output
- `None`: Transform configuration is unchanged

.. versionadded:: 1.2

Expand Down Expand Up @@ -231,7 +238,14 @@ def config_context(
.. versionadded:: 1.2

transform_output : str, default=None
Configure the output container for transform.
Configure output of `transform` and `fit_transform`.

See :ref:`sphx_glr_auto_examples_miscellaneous_plot_set_output.py`
for an example on how to use the API.

- `"default"`: Default output format of a transformer
- `"pandas"`: DataFrame output
- `None`: Transform configuration is unchanged

.. versionadded:: 1.2

Expand Down
6 changes: 3 additions & 3 deletions sklearn/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,9 +808,9 @@ def get_submatrix(self, i, data):
class TransformerMixin(_SetOutputMixin):
"""Mixin class for all transformers in scikit-learn.

If :term:`get_feature_names_out` is defined and `auto_wrap_output` is True,
then `BaseEstimator` will automatically wrap `transform` and `fit_transform` to
follow the `set_output` API. See the :ref:`developer_api_set_output` for details.
If :term:`get_feature_names_out` is defined, then `BaseEstimator` will
automatically wrap `transform` and `fit_transform` to follow the `set_output`
API. See the :ref:`developer_api_set_output` for details.
"""

def fit_transform(self, X, y=None, **fit_params):
Expand Down
4 changes: 4 additions & 0 deletions sklearn/compose/_column_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ def set_output(self, transform=None):
transform : {"default", "pandas"}, default=None
Configure output of `transform` and `fit_transform`.

- `"default"`: Default output format of a transformer
- `"pandas"`: DataFrame output
- `None`: Transform configuration is unchanged

Returns
-------
self : estimator instance
Expand Down
8 changes: 8 additions & 0 deletions sklearn/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ def set_output(self, transform=None):
transform : {"default", "pandas"}, default=None
Configure output of `transform` and `fit_transform`.

- `"default"`: Default output format of a transformer
- `"pandas"`: DataFrame output
- `None`: Transform configuration is unchanged

Returns
-------
self : estimator instance
Expand Down Expand Up @@ -999,6 +1003,10 @@ def set_output(self, transform=None):
transform : {"default", "pandas"}, default=None
Configure output of `transform` and `fit_transform`.

- `"default"`: Default output format of a transformer
- `"pandas"`: DataFrame output
- `None`: Transform configuration is unchanged

Returns
-------
self : estimator instance
Expand Down
9 changes: 4 additions & 5 deletions sklearn/preprocessing/_function_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,11 @@ def set_output(self, *, transform=None):
Parameters
----------
transform : {"default", "pandas"}, default=None
Configure output of the following estimator's methods:
Configure output of `transform` and `fit_transform`.

- `"transform"`
- `"fit_transform"`

If `None`, this operation is a no-op.
- `"default"`: Default output format of a transformer
- `"pandas"`: DataFrame output
- `None`: Transform configuration is unchanged

Returns
-------
Expand Down
11 changes: 5 additions & 6 deletions sklearn/utils/_set_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class _SetOutputMixin:
it based on `set_output` of the global configuration.

`set_output` is only defined if `get_feature_names_out` is defined and
`auto_wrap_output` is True.
`auto_wrap_output_keys` is the default value.
"""

def __init_subclass__(cls, auto_wrap_output_keys=("transform",), **kwargs):
Expand Down Expand Up @@ -206,12 +206,11 @@ def set_output(self, *, transform=None):
Parameters
----------
transform : {"default", "pandas"}, default=None
Configure output of the following estimator's methods:
Configure output of `transform` and `fit_transform`.

- `"transform"`
- `"fit_transform"`

If `None`, this operation is a no-op.
- `"default"`: Default output format of a transformer
- `"pandas"`: DataFrame output
- `None`: Transform configuration is unchanged

Returns
-------
Expand Down