import numpy as np
from sklearn.metrics import precision_score, recall_score, f1_score
y_true = np.array([[0, 1, 1],
[0, 1, 0]])
y_pred = np.array([[1, 1, 1],
[0, 0, 1]])
# 1行 N列
y_true = np.reshape(y_true, [-1])
y_pred = np.reshape(y_pred, [-1])
print(y_pred)
print(y_true)
# True Positive(TP):真实为正,预测为正;
# true positive
TP = np.sum(np.logical_and(np.equal(y_true, 1), np.equal(y_pred, 1)))
print('TP =', TP)
# False Positive(FP):真实为负,预测为正;
# false positive
FP = np.sum(np.logical_and(np.equal(y_true, 0), np.equal(y_pred, 1)))
print('FP =', FP)
# True Negative(TN):真实为负,预测为负;
# true negative
TN = np.sum(np.logical_and(np.equal(y_true, 0), np.equal(y_pred, 0)))
print('TN =', TN)
# False Negative(FN):真实为正,预测为负;
# false negative
FN = np.sum(np.logical_and
查准率、查全率、F1度量的原理及使用
最新推荐文章于 2022-04-21 18:01:33 发布