Skip to content

Pipeline pop #8448

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

Closed
wants to merge 2 commits into from
Closed

Pipeline pop #8448

wants to merge 2 commits into from

Conversation

jnothman
Copy link
Member

Conceptually Fixes #8414 and related issues. Alternative to #8431, #2568, #2561, #2562, focusing on extracting one specified estimator.

Designed to assist in model inspection and particularly to replicate the
composite transformer represented by steps of the pipeline with the
exception of the last. I.e. transformer, predictor = pipe.pop() is a common
idiom. I feel like this becomes more necessary when considering more
API-consistent clone behaviour as per #8350 as Pipeline(pipe.steps[:-1]).inverse_transform(Xt)
is no longer possible.

Note that once #8350 is merged, I intend that the popped estimator reflect the instance in steps_. I'm not sure what behaviour should be when the Pipeline is not fitted and pop is called.

Ping @glemaitre, @GaelVaroquaux

TODO:

Conceptually Fixes scikit-learn#8414 and related issues. Alternative to scikit-learn#2568
without __getitem__ and mixed semantics.

Designed to assist in model inspection and particularly to replicate the
composite transformer represented by steps of the pipeline with the
exception of the last. I.e. pipe.get_subsequence(0, -1) is a common
idiom. I feel like this becomes more necessary when considering more
API-consistent clone behaviour as per scikit-learn#8350 as Pipeline(pipe.steps[:-1])
is no longer possible.
@codecov
Copy link

codecov bot commented Feb 24, 2017

Codecov Report

Merging #8448 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #8448      +/-   ##
==========================================
+ Coverage   95.47%   95.48%   +<.01%     
==========================================
  Files         342      342              
  Lines       60907    60946      +39     
==========================================
+ Hits        58154    58193      +39     
  Misses       2753     2753
Impacted Files Coverage Δ
sklearn/tests/test_pipeline.py 99.63% <100%> (+0.02%)
sklearn/pipeline.py 99.28% <100%> (+0.02%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7f084b0...a60cc33. Read the comment docs.

@glemaitre
Copy link
Member

@jnothman I am for checking that the Pipeline was fitted.

I don't see the user case for popping an unfitted Pipeline despite if one wants to avoid rebuilding a Pipeline instance from scratch.

@jnothman
Copy link
Member Author

jnothman commented Feb 25, 2017 via email

@amueller
Copy link
Member

I would add an optional "start" though I don't have a strong opinion about it.

@amueller
Copy link
Member

I wouldn't return the popped-off element, I think that's rarely useful.
Either way it doesn't have the same interface as dict.pop or DataFrame.pop which only return the popped element.

Checking whether it's fitted or not doesn't make a difference now but will in the future if we clone. That was the discussion point, right?

@jnothman
Copy link
Member Author

jnothman commented Nov 28, 2018 via email

@amueller
Copy link
Member

I don't have a strong opinion on this.
Getting the last step is also easy with pipe.steps_[-1][1] or pipe.named_steps.name_of_estimator

@jnothman
Copy link
Member Author

jnothman commented Nov 28, 2018 via email

@amueller
Copy link
Member

How would you implement that? Using __getitem__?
I am warming to head for a slice and I feel we already have good ways to get single elements.
Head could have a skip to not start at the first if you don't want to include the first. I think this is a rarer use-case, though.

@jnothman
Copy link
Member Author

jnothman commented Dec 3, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants