MCPcopy Create free account
hub / github.com/modAL-python/modAL / classifier_uncertainty

Function classifier_uncertainty

modAL/uncertainty.py:63–83  ·  view source on GitHub ↗

Classification uncertainty of the classifier for the provided samples. Args: classifier: The classifier for which the uncertainty is to be measured. X: The samples for which the uncertainty of classification is to be measured. **predict_proba_kwargs: Keyword argumen

(classifier: BaseEstimator, X: modALinput, **predict_proba_kwargs)

Source from the content-addressed store, hash-verified

61
62
63def classifier_uncertainty(classifier: BaseEstimator, X: modALinput, **predict_proba_kwargs) -> np.ndarray:
64 """
65 Classification uncertainty of the classifier for the provided samples.
66
67 Args:
68 classifier: The classifier for which the uncertainty is to be measured.
69 X: The samples for which the uncertainty of classification is to be measured.
70 **predict_proba_kwargs: Keyword arguments to be passed for the :meth:`predict_proba` of the classifier.
71
72 Returns:
73 Classifier uncertainty, which is 1 - P(prediction is correct).
74 """
75 # calculate uncertainty for each point provided
76 try:
77 classwise_uncertainty = classifier.predict_proba(X, **predict_proba_kwargs)
78 except NotFittedError:
79 return np.ones(shape=(X.shape[0], ))
80
81 # for each point, select the maximum uncertainty
82 uncertainty = 1 - np.max(classwise_uncertainty, axis=1)
83 return uncertainty
84
85
86def classifier_margin(classifier: BaseEstimator, X: modALinput, **predict_proba_kwargs) -> np.ndarray:

Calls 1

predict_probaMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…