Skip to content

Make use of check_is_fitted instead of manual checks #12991

@agamemnonc

Description

@agamemnonc

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:

if not hasattr(self, 'coef_') or self.coef_ is None:
raise NotFittedError("This %(name)s instance is not fitted "
"yet" % {'name': type(self).__name__})

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions