def get_metric_value(self, reset: bool = False ) -> Union[float, Dict[str, float]]: if not self.is_initialized: logger.warning( "Trying to get not initialized metric, returning 0.") return 0.0 mcm = self.multilabel_confusion_matrix numerator = mcm[..., 1, 1] denominator = mcm[..., 1, 1] + mcm[..., 1, 0] precision = self._reduce_metric(numerator / denominator) self._reset_if_needed(reset) return precision
def get_metric_value(self, reset: bool = False ) -> Union[float, Dict[str, float]]: if not self.is_initialized: logger.warning( "Trying to get not initialized metric, returning 0.") return 0.0 mcm = self.multilabel_confusion_matrix tp_sum = mcm[:, 1, 1] pred_sum = tp_sum + mcm[:, 0, 1] true_sum = tp_sum + mcm[:, 1, 0] precision = tp_sum / pred_sum recall = tp_sum / true_sum f_score = ((1 + self.beta2) * precision * recall / (self.beta2 * precision + recall)) f_score = self._reduce_metric(f_score) self._reset_if_needed(reset) return f_score