提交 16e8a5f1 编写于 作者: J Jason N 提交者: Meiyim

Update metrics.py

修改了Precision, Recall, F1中的bug
上级 f8c0fb44
...@@ -173,8 +173,8 @@ class Precision(Metrics): ...@@ -173,8 +173,8 @@ class Precision(Metrics):
def eval(self): def eval(self):
"""doc""" """doc"""
tp = (self.label_saver & self.pred_saver).astype(np.int64).sum() tp = (self.label_saver & self.pred_saver).astype(np.int64).sum()
t = self.label_saver.astype(np.int64).sum() p = self.pred_saver.astype(np.int64).sum()
return tp / t return tp / p
class Recall(Precision): class Recall(Precision):
...@@ -183,8 +183,8 @@ class Recall(Precision): ...@@ -183,8 +183,8 @@ class Recall(Precision):
def eval(self): def eval(self):
"""doc""" """doc"""
tp = (self.label_saver & self.pred_saver).astype(np.int64).sum() tp = (self.label_saver & self.pred_saver).astype(np.int64).sum()
p = (self.label_saver).astype(np.int64).sum() t = (self.label_saver).astype(np.int64).sum()
return tp / p return tp / t
class F1(Precision): class F1(Precision):
...@@ -195,8 +195,8 @@ class F1(Precision): ...@@ -195,8 +195,8 @@ class F1(Precision):
tp = (self.label_saver & self.pred_saver).astype(np.int64).sum() tp = (self.label_saver & self.pred_saver).astype(np.int64).sum()
t = self.label_saver.astype(np.int64).sum() t = self.label_saver.astype(np.int64).sum()
p = self.pred_saver.astype(np.int64).sum() p = self.pred_saver.astype(np.int64).sum()
precision = tp / (t + 1.e-6) precision = tp / (p + 1.e-6)
recall = tp / (p + 1.e-6) recall = tp / (t + 1.e-6)
return 2 * precision * recall / (precision + recall + 1.e-6) return 2 * precision * recall / (precision + recall + 1.e-6)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册