Skip to content

SLEP013: n_features_out_ #29

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 9 commits into from
Feb 19, 2020
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@ docs/_build/

# PyBuilder
target/

# Editors
.vscode
71 changes: 71 additions & 0 deletions slep013/proposal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
.. _slep_013:

======================================
SLEP013: ``n_features_out_`` attribute
======================================

:Author: Adrin Jalali
:Status: Under Review
:Type: Standards Track
:Created: 2020-02-12

Abstract
########

This SLEP proposes the introduction of a public ``n_features_out_`` attribute
for most transformers (where relevant).

Motivation
##########

Knowing the number of features that a transformer outputs is useful for
inspection purposes. This is in conjunction with `*SLEP010: ``n_features_in_``*
<https://scikit-learn-enhancement-proposals.readthedocs.io/en/latest/slep010/proposal.html>`_.

Solution
########

The proposed solution is for the ``n_features_out_`` attribute to be set once a
call to ``fit`` is done. In many cases the value of ``n_features_out_`` is the
same as some other attribute stored in the transformer, *e.g.*
``n_components_``, and in these cases a ``Mixin`` such as a ``ComponentsMixin``
can delegate ``n_features_out_`` to those attributes.

Testing
-------

A test to the common tests is added to ensure the presence of the attribute or
property after calling ``fit``.

Considerations
##############

The main consideration is that the addition of the common test means that
existing estimators in downstream libraries will not pass our test suite,
unless the estimators also have the ``n_features_out_`` attribute.

The newly introduced checks will only raise a warning instead of an exception
for the next 2 releases, so this will give more time for downstream packages
to adjust.

There are other minor considerations:

- In some meta-estimators, this is delegated to the
sub-estimator(s). The ``n_features_out_`` attribute of the meta-estimator is
thus explicitly set to that of the sub-estimator, either via a ``@property``,
or directly in ``fit()``.
- Some transformers such as ``FunctionTransformer`` may not know the number
of output features since arbitrary arrays can be passed to `transform`. In
such cases ``n_features_out_`` is set to ``None``.

Copyright
---------

This document has been placed in the public domain. [1]_

References and Footnotes
------------------------

.. [1] _Open Publication License: https://www.opencontent.org/openpub/


1 change: 1 addition & 0 deletions under_review.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ SLEPs under review

slep007/proposal
slep012/proposal
slep013/proposal