Skip to content

Adding get_estimated method to pipelines #2562

@schwarty

Description

@schwarty

The motivation is the same as PR #2561. In a nutshell, we want to be able to apply
the inverse_transform steps from a pipeline on an estimated parameter from the last step of the same pipeline. PR #2561 aims to achieve that goal by applying the inverse_transforms from all steps, except the last one if it misses an inverse_transform method. @GaelVaroquaux pointed out that it will fail in the cases where the last estimator implements both transform/inverse_transform methods and predict/score methods.

The alternative could be to implement a get_estimated method for Pipelines that explicitly retrieves a given attribute from the pipeline last step, and subsequently applies the inverse_transforms. The code would look like the following:

pca = PCA()
clf = LinearSVC()
pipeline = Pipeline([('pca', pca), ('clf', clf)])

pipeline.fit(X, y)
coef_ = pipeline.get_estimated('coef_')

assert X.shape[1] == coef_.shape[1]

Note that the final learner may itself be a Pipeline, a GridSearchCV, a MetaClassifier, or any valid combination in sklearn.

Any comments, suggestions?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions