Make classifier evaluation metrics work when tp+fp=0

pull/3/head
Alinson S. Xavier 6 years ago
parent 5b02c6ea0e
commit 907c4fe14a

@ -18,12 +18,18 @@ def classifier_evaluation_dict(tp, tn, fp, fn):
"Accuracy": (tp + tn) / (p + n),
"F1 score": (2 * tp) / (2 * tp + fp + fn),
}
if p > 0:
d["Recall"] = tp / p
d["Precision"] = tp / (tp + fp)
else:
d["Recall"] = 1.0
if tp + fp > 0:
d["Precision"] = tp / (tp + fp)
else:
d["Precision"] = 1.0
t = (p + n) / 100.0
d["Predicted positive (%)"] = d["Predicted positive"] / t
d["Predicted negative (%)"] = d["Predicted negative"] / t

Loading…
Cancel
Save