scikit-learn/scikit-learn — pull request #2630 by jcrudy (2013-12-02 20:12:45+00:00)
Title: Make Pipeline compatible with AdaBoost

This pull request makes the following changes to the Pipeline class:

1. Allow passing arguments to methods of steps, not just their constructors. Necessary so that AdaBoost can pass the sample_weight argument.

2. If an argument is not of the form step__argname it will be passed to all steps. Necessary again so that AdaBoost can pass the sample_weight argument.

3. Forward attribute access to steps if the attribute is not found in the Pipeline object itself. Steps are searched backward starting with the final step. Allows AdaBoostClassifier to access the classes_ attribute of the final classifier in the Pipeline.

My objective was to make changes that would generalize well to other potential uses of the Pipeline. For example, it is now possible to pass an argument to the fit method of a particular step by passing a parameter named step__argname instead of just argname. It is also possible to access step attributes other than the classes_ attribute of the final step. Neither of these features is strictly necessary to get AdaBoost compatibility, but seemed like reasonable generalizations of the necessary functionality. I think sklearn devs should pay particular attention to change 3 above and make sure they're comfortable with it. There are definitely other generalizations that might be better, such as only allowing access to the attributes of the final step or even only forwarding the classes_ attribute.

A gist showing the intended usage of this enhancement is located here:

https://gist.github.com/jcrudy/7756798

The gist uses py-earth because I was not familiar with a scikit-learn transformer that takes sample_weight (I don't know them all, though). If the EarthRegressor (https://github.com/scikit-learn/scikit-learn/pull/2285) pull request is merged then there will be at least one such transformer.