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

Function check_classifiers_one_label

sklearn/utils/estimator_checks.py:2920–2940  ·  view source on GitHub ↗
(name, classifier_orig)

Source from the content-addressed store, hash-verified

2918
2919@ignore_warnings(category=FutureWarning)
2920def check_classifiers_one_label(name, classifier_orig):
2921 error_string_fit = "Classifier can't train when only one class is present."
2922 error_string_predict = "Classifier can't predict when only one class is present."
2923 classifier = clone(classifier_orig)
2924 rnd = np.random.RandomState(0)
2925 X_train = rnd.uniform(size=(10, 3))
2926 X_test = rnd.uniform(size=(10, 3))
2927 X_train, X_test = _enforce_estimator_tags_X(classifier, X_train, X_test=X_test)
2928 y = np.ones(10)
2929 # catch deprecation warnings
2930 with ignore_warnings(category=FutureWarning):
2931 with raises(
2932 ValueError, match="class", may_pass=True, err_msg=error_string_fit
2933 ) as cm:
2934 classifier.fit(X_train, y)
2935
2936 if cm.raised_and_matched:
2937 # ValueError was raised with proper error message
2938 return
2939
2940 assert_array_equal(classifier.predict(X_test), y, err_msg=error_string_predict)
2941
2942
2943@ignore_warnings(category=FutureWarning)

Callers

nothing calls this directly

Calls 6

cloneFunction · 0.90
ignore_warningsFunction · 0.90
raisesFunction · 0.90
fitMethod · 0.45
predictMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…