sklearn.utils.validation.check_is_fitted

sklearn.utils.validation.check_is_fitted(estimator, attributes, msg=None, all_or_any=<built-in function all>)[source]

Perform is_fitted validation for estimator.

Checks if the estimator is fitted by verifying the presence of “all_or_any” of the passed attributes and raises a NotFittedError with the given message.

Parameters:
estimator : estimator instance.

estimator instance for which the check is performed.

attributes : attribute name(s) given as string or a list/tuple of strings
Eg.:

["coef_", "estimator_", ...], "coef_"

msg : string

The default error message is, “This %(name)s instance is not fitted yet. Call ‘fit’ with appropriate arguments before using this method.”

For custom messages if “%(name)s” is present in the message string, it is substituted for the estimator name.

Eg. : “Estimator, %(name)s, must be fitted before sparsifying”.

all_or_any : callable, {all, any}, default all

Specify whether all or any of the given attributes must exist.

Returns:
None
Raises:
NotFittedError

If the attributes are not found.