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)
| 61 | |
| 62 | |
| 63 | def 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 | |
| 86 | def classifier_margin(classifier: BaseEstimator, X: modALinput, **predict_proba_kwargs) -> np.ndarray: |
no test coverage detected
searching dependent graphs…