From 09e12757c38c66ff2356b3ad74e17047b507d198 Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Wed, 12 Feb 2020 15:51:36 +0100 Subject: [PATCH 1/8] SLEP012: n_features_out_ --- .gitignore | 3 +++ slep012/proposal.rst | 63 ++++++++++++++++++++++++++++++++++++++++++++ under_review.rst | 8 +++--- 3 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 slep012/proposal.rst diff --git a/.gitignore b/.gitignore index ba74660..de69825 100644 --- a/.gitignore +++ b/.gitignore @@ -55,3 +55,6 @@ docs/_build/ # PyBuilder target/ + +# Editors +.vscode diff --git a/slep012/proposal.rst b/slep012/proposal.rst new file mode 100644 index 0000000..9ff7a3a --- /dev/null +++ b/slep012/proposal.rst @@ -0,0 +1,63 @@ +.. _slep_012: + +====================================== +SLEP012: ``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. + +Solution +######## + +The proposed solution is for the ``n_features_out_`` attribute to be set once a +call to ``fit`` is done. In most 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. + +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 most meta-estimators, this is handled by 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. 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/ + + diff --git a/under_review.rst b/under_review.rst index 2f1bcd3..72f95b4 100644 --- a/under_review.rst +++ b/under_review.rst @@ -1,11 +1,11 @@ SLEPs under review ================== -No SLEP is currently under review. +.. No SLEP is currently under review. .. Uncomment below when a SLEP is under review -.. .. toctree:: -.. :maxdepth: 1 +.. toctree:: + :maxdepth: 1 -.. slepXXX/proposal + slep012/proposal From 5d9f4049dbcd6b05971a45959894a07f2eff0628 Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Wed, 12 Feb 2020 15:53:40 +0100 Subject: [PATCH 2/8] mention n_features_in_ --- slep012/proposal.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slep012/proposal.rst b/slep012/proposal.rst index 9ff7a3a..fe16b1a 100644 --- a/slep012/proposal.rst +++ b/slep012/proposal.rst @@ -19,7 +19,7 @@ Motivation ########## Knowing the number of features that a transformer outputs is useful for -inspection purposes. +inspection purposes. This is in conjunction with *SLEP010: ``n_features_in_``*. Solution ######## From 2d5e88f0df95c24f6b721bff6ff5a4a976addf41 Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Thu, 13 Feb 2020 15:47:32 +0100 Subject: [PATCH 3/8] add link to n_features_in_ and mention the new test --- slep012/proposal.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/slep012/proposal.rst b/slep012/proposal.rst index fe16b1a..1c001f3 100644 --- a/slep012/proposal.rst +++ b/slep012/proposal.rst @@ -19,7 +19,8 @@ Motivation ########## Knowing the number of features that a transformer outputs is useful for -inspection purposes. This is in conjunction with *SLEP010: ``n_features_in_``*. +inspection purposes. This is in conjunction with `*SLEP010: ``n_features_in_``* +`_. Solution ######## @@ -30,6 +31,12 @@ 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 ############## From 01bab58b8361c3aa032f9bda6c5b3ccc3343fecc Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Thu, 13 Feb 2020 16:22:28 +0100 Subject: [PATCH 4/8] more Nicolas's changes --- slep012/proposal.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/slep012/proposal.rst b/slep012/proposal.rst index 1c001f3..f762b80 100644 --- a/slep012/proposal.rst +++ b/slep012/proposal.rst @@ -50,12 +50,13 @@ to adjust. There are other minor considerations: -- In most meta-estimators, this is handled by the +- In most 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. In such cases ``n_features_out_`` is set to ``None``. + of output features since arbitrary arrays can be passed to `transform`. In + such cases ``n_features_out_`` is set to ``None``. Copyright --------- From da14bcdc20e291aa15128be1fc88e43fa4a37ef9 Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Thu, 13 Feb 2020 16:36:14 +0100 Subject: [PATCH 5/8] most -> some --- slep012/proposal.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slep012/proposal.rst b/slep012/proposal.rst index f762b80..e39456b 100644 --- a/slep012/proposal.rst +++ b/slep012/proposal.rst @@ -50,7 +50,7 @@ to adjust. There are other minor considerations: -- In most meta-estimators, this is delegated to the +- 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()``. From a4a84eb812afd7e6dc2b81d41777067428558d6f Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Tue, 18 Feb 2020 14:54:03 +0100 Subject: [PATCH 6/8] most -> many --- slep012/proposal.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slep012/proposal.rst b/slep012/proposal.rst index e39456b..61eb118 100644 --- a/slep012/proposal.rst +++ b/slep012/proposal.rst @@ -26,7 +26,7 @@ Solution ######## The proposed solution is for the ``n_features_out_`` attribute to be set once a -call to ``fit`` is done. In most cases the value of ``n_features_out_`` is the +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. From 58354ba548e880576d55212d24f37d4ca76ad2b2 Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Wed, 19 Feb 2020 15:36:10 +0100 Subject: [PATCH 7/8] rename to slep13 --- {slep012 => slep013}/proposal.rst | 2 +- under_review.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename {slep012 => slep013}/proposal.rst (99%) diff --git a/slep012/proposal.rst b/slep013/proposal.rst similarity index 99% rename from slep012/proposal.rst rename to slep013/proposal.rst index 61eb118..649b036 100644 --- a/slep012/proposal.rst +++ b/slep013/proposal.rst @@ -1,4 +1,4 @@ -.. _slep_012: +.. _slep_013: ====================================== SLEP012: ``n_features_out_`` attribute diff --git a/under_review.rst b/under_review.rst index 72f95b4..4385333 100644 --- a/under_review.rst +++ b/under_review.rst @@ -8,4 +8,4 @@ SLEPs under review .. toctree:: :maxdepth: 1 - slep012/proposal + slep013/proposal From 3e7b46037f410b72abc44ef27593c3c125ebc6fa Mon Sep 17 00:00:00 2001 From: adrinjalali Date: Wed, 19 Feb 2020 17:34:57 +0100 Subject: [PATCH 8/8] missed slep12->slep13 --- slep013/proposal.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slep013/proposal.rst b/slep013/proposal.rst index 649b036..4744aaa 100644 --- a/slep013/proposal.rst +++ b/slep013/proposal.rst @@ -1,7 +1,7 @@ .. _slep_013: ====================================== -SLEP012: ``n_features_out_`` attribute +SLEP013: ``n_features_out_`` attribute ====================================== :Author: Adrin Jalali