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)
| 84 | |
| 85 | |
| 86 | def 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 | |
| 113 | def classifier_entropy(classifier: BaseEstimator, X: modALinput, **predict_proba_kwargs) -> np.ndarray: |
no test coverage detected
searching dependent graphs…