-
-
Notifications
You must be signed in to change notification settings - Fork 26.5k
Description
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.