我正在为一个高度不平衡的分类问题实现一个CNN,我想在tensorflow中实现客户指标,以使用Select Best Model回调。具体地说,我想实现平衡的准确率分数,这是每个类的召回率的平均值(参见sklearn implementation here),有人知道如何做到这一点吗?
发布于 2020-03-17 04:44:16
我还没有测试过这段代码,,但是看看tensorflow==2.1.0的source code,这可能适用于二进制分类的情况:
from tensorflow.keras.metrics import Recall
from tensorflow.python.ops import math_ops
class BalancedBinaryAccuracy(Recall):
def result(self):
result = (math_ops.div_no_nan(self.true_positives, self.true_positives + self.false_negatives) +
math_ops.div_no_nan(self.true_negatives, self.true_negatives + self.false_positives)) / 2
return result[0] if len(self.thresholds) == 1 else resulthttps://stackoverflow.com/questions/59339531
复制相似问题