-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
Make use of check_is_fitted instead of manual checks #12991
Description
Description
In some places, a manual check is performed to check whether an estimator has been fitted, instead of using the check_is_fitted method. Due to this, the NotFittedError messages are often inconsistent.
Some examples include:
scikit-learn/sklearn/linear_model/base.py
Lines 253 to 255 in 486f8fc
| if not hasattr(self, 'coef_') or self.coef_ is None: | |
| raise NotFittedError("This %(name)s instance is not fitted " | |
| "yet" % {'name': type(self).__name__}) |
scikit-learn/sklearn/linear_model/logistic.py
Lines 1645 to 1646 in 486f8fc
| if not hasattr(self, "coef_"): | |
| raise NotFittedError("Call fit before prediction") |
Steps/Code to Reproduce
Look at the code in the examples above.
Expected Results
Code should be using the check_is_fitted method from the utils.validation submodule.
Actual Results
This check is re-implemented in various places. Error messages are not consistent.
Versions
n/a
TODO
I am happy to submit a PR to fix this. Planning to identify the places where the method is re-implemented using the search functionality on github. Please let me know if there is more clever way of doing this.