阅读背景:

sklearn的precision_score, recall_score, f1_score使用

来源:互联网 

1 使用numpy计算true positives等

import numpy as np

y_true = np.array([0, 1, 1, 0, 1, 0])
y_pred = np.array([1, 1, 1, 0, 0, 1])

# true positive
TP = np.sum(np.multiply(y_true, y_pred))
print(TP)

# false positive
FP = np.sum(np.logical_and(np.equal(y_true, 0), np.equal(y_pred, 1)))
print(FP)

# false negative
FN = np.sum(np.logical_and(np.equal(y_true, 1), np.equal(y_pred, 0)))
print(FN)

# true negative
TN = np.sum(np.logical_and(np.equal(y_true, 0), np.equal(y_pred, 0)))
print(TN)import numpy as



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: