is_fitted#
- pybear.base.is_fitted(estimator, attributes=None, all_or_any=<built-in function all>)#
Determine if an estimator/transformer is fitted and return a boolean.
‘True’ means fitted and ‘False’ means not fitted.
This algorithm looks for 3 things, in the presented order.
- The estimator/transformer is fitted if it:
- has a __pybear_is_fitted__ dunder method and it returns
boolean True
- has any or all attributes given by attributes, if it is
passed; if not passed, this step is skipped
- has an attribute that ends with an underscore and does not
start with double underscore.
- Parameters:
- estimatorobject
Estimator/transformer instance for which the check is performed.
- attributesstr | Sequence[str] | None, default=None
Attribute name(s) given as string or a list/tuple of strings Eg.: ‘coef_’ or [’coef_’, ‘estimator_’, …]
- all_or_anycallable, {all, any}, default=all
Specifies whether all or any of the given attributes must exist.
- Returns:
- fittedbool
Whether the estimator/transformer is fitted.
Examples
>>> from pybear.base._is_fitted import is_fitted >>> from pybear.preprocessing import InterceptManager as IM >>> trf = IM() >>> is_fitted(trf) False >>> import numpy as np >>> X = np.random.uniform(0, 1, (5,3)) >>> trf.fit(X) InterceptManager() >>> is_fitted(trf) True