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

Function classifier_margin

modAL/uncertainty.py:86–110  ·  view source on GitHub ↗

Classification margin uncertainty of the classifier for the provided samples. This uncertainty measure takes the first and second most likely predictions and takes the difference of their probabilities, which is the margin. Args: classifier: The classifier for which the predict

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

Source from the content-addressed store, hash-verified

84
85
86def classifier_margin(classifier: BaseEstimator, X: modALinput, **predict_proba_kwargs) -> np.ndarray:
87 """
88 Classification margin uncertainty of the classifier for the provided samples. This uncertainty measure takes the
89 first and second most likely predictions and takes the difference of their probabilities, which is the margin.
90
91 Args:
92 classifier: The classifier for which the prediction margin is to be measured.
93 X: The samples for which the prediction margin of classification is to be measured.
94 **predict_proba_kwargs: Keyword arguments to be passed for the :meth:`predict_proba` of the classifier.
95
96 Returns:
97 Margin uncertainty, which is the difference of the probabilities of first and second most likely predictions.
98 """
99 try:
100 classwise_uncertainty = classifier.predict_proba(X, **predict_proba_kwargs)
101 except NotFittedError:
102 return np.zeros(shape=(X.shape[0], ))
103
104 if classwise_uncertainty.shape[1] == 1:
105 return np.zeros(shape=(classwise_uncertainty.shape[0],))
106
107 part = np.partition(-classwise_uncertainty, 1, axis=1)
108 margin = - part[:, 0] + part[:, 1]
109
110 return margin
111
112
113def classifier_entropy(classifier: BaseEstimator, X: modALinput, **predict_proba_kwargs) -> np.ndarray:

Callers 2

margin_samplingFunction · 0.85

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…