MCPcopy
hub / github.com/scikit-learn/scikit-learn / test_check_is_fitted

Function test_check_is_fitted

sklearn/utils/tests/test_validation.py:960–993  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

958
959
960def test_check_is_fitted():
961 # Check is TypeError raised when non estimator instance passed
962 with pytest.raises(TypeError):
963 check_is_fitted(ARDRegression)
964 with pytest.raises(TypeError):
965 check_is_fitted("SVR")
966
967 ard = ARDRegression()
968 svr = SVR()
969
970 try:
971 with pytest.raises(NotFittedError):
972 check_is_fitted(ard)
973 with pytest.raises(NotFittedError):
974 check_is_fitted(svr)
975 except ValueError:
976 assert False, "check_is_fitted failed with ValueError"
977
978 # NotFittedError is a subclass of both ValueError and AttributeError
979 msg = "Random message %(name)s, %(name)s"
980 match = "Random message ARDRegression, ARDRegression"
981 with pytest.raises(ValueError, match=match):
982 check_is_fitted(ard, msg=msg)
983
984 msg = "Another message %(name)s, %(name)s"
985 match = "Another message SVR, SVR"
986 with pytest.raises(AttributeError, match=match):
987 check_is_fitted(svr, msg=msg)
988
989 ard.fit(*make_blobs())
990 svr.fit(*make_blobs())
991
992 assert check_is_fitted(ard) is None
993 assert check_is_fitted(svr) is None
994
995
996def test_check_is_fitted_attributes():

Callers

nothing calls this directly

Calls 6

fitMethod · 0.95
check_is_fittedFunction · 0.90
ARDRegressionClass · 0.90
SVRClass · 0.90
make_blobsFunction · 0.90
fitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…