Toggle Menu
Prev Up Next

scikit-learn 1.3.2
Other versions

Please cite us if you use the software.

# `sklearn.utils.validation`.check_is_fitted

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

  Perform is_fitted validation for estimator.

  Checks if the estimator is fitted by verifying the presence of fitted attributes (ending with a trailing underscore) and otherwise raises a NotFittedError with the given message.

  If an estimator does not set any attributes with a trailing underscore, it can define a `__sklearn_is_fitted__` method returning a boolean to specify if the estimator is fitted or not.

  Parameters:
    estimator estimator instance

      Estimator instance for which the check is performed.

    attributes str, list or tuple of str, default=None

      Attribute name(s) given as string or a list/tuple of strings Eg.: `["coef_", "estimator_", ...], "coef_"`

      If `None`, `estimator` is considered fitted if there exist an attribute that ends with a underscore and does not start with double underscore.

    msg str, default=None

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

      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.

  Raises:
    TypeError

      If the estimator is a class or not an estimator instance

    NotFittedError

      If the attributes are not found.

## Examples using `sklearn.utils.validation.check_is_fitted`

Inductive Clustering

Inductive Clustering

__sklearn_is_fitted__ as Developer API

__sklearn_is_fitted__ as Developer API

Metadata Routing

Metadata Routing