8000 Problem with ducktyping and meta-estimators · Issue #1805 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content
Problem with ducktyping and meta-estimators #1805
Closed
@jnothman

Description

@jnothman

In a number of places, sklearn controls flow according to the existence of some method on an estimator. For example: *SearchCV.score checks for score on the estimator; Scorer and multiclass functions check for decision_function; and it is used for validation in AdaBoostClassifier.fit, multiclass._check_estimator and Pipeline; and for testing in test_common.

Meta-estimators such as *SearchCV, Pipeline, RFECV, etc. should respond to such hasattrs in agreement with their underlying estimators (or else the hasattr approach should be avoided).

This is possible by implementing such methods with a property that returns the correct method from the sub-estimator (or a closure around it), or raises AttributeError if the sub-estimator is found lacking (see #1801). hasattr would then function correctly. Caveats: the code would be less straightforward in some cases; help()/pydoc won't show the methods as methods (with an argument list, etc.), though the property's docstring will show.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0