def test_clf_with_nan(self, input_data, expected_value): params = input_data.copy() vals = {} vals["y_pred"] = params.pop("y_pred") vals["y"] = params.pop("y") metric = ConfusionMatrixMetric(**params) result = metric(**vals) np.testing.assert_allclose(result, expected_value, atol=1e-4, rtol=1e-4) result, _ = metric.aggregate(reduction="mean_channel")[0] expected_value, _ = do_metric_reduction(expected_value, "mean_channel") expected_value = compute_confusion_matrix_metric("tpr", expected_value) np.testing.assert_allclose(result, expected_value, atol=1e-4, rtol=1e-4)
def compute(self): """ Raises: NotComputableError: When ``compute`` is called before an ``update`` occurs. """ if self.compute_sample is True: if self._num_examples == 0: raise NotComputableError( "ConfusionMatrix metric must have at least one example before it can be computed." ) return self._sum / self._num_examples confusion_matrix = torch.tensor( [self._total_tp, self._total_fp, self._total_tn, self._total_fn]) return compute_confusion_matrix_metric(self.metric_name, confusion_matrix)
def _reduce(self, scores) -> Any: confusion_matrix, _ = do_metric_reduction(scores, MetricReduction.MEAN) return compute_confusion_matrix_metric(self.metric_name, confusion_matrix)