【发布时间】:2022-12-30 00:10:17
【问题描述】:
我在这里有实际的课程和 res 课程 - https://extendsclass.com/csv-editor.html#46eaa9e
我想计算每个 A、N、O 类的敏感性、特异性和阳性预测率。这是我的代码
这是代码
from sklearn.metrics import multilabel_confusion_matrix
import numpy as np
mcm = multilabel_confusion_matrix(act_class, pred_class)
tps = mcm[:, 1, 1]
tns = mcm[:, 0, 0]
recall = tps / (tps + mcm[:, 1, 0]) # Sensitivity
specificity = tns / (tns + mcm[:, 0, 1]) # Specificity
precision = tps / (tps + mcm[:, 0, 1]) # PPV
print(recall)
print(specificity)
print(precision)
print(classification_report(act_class, pred_class))
这给了我这样的结果
[0.31818182 0.96186441 nan nan]
[0.99576271 0.86363636 0.86092715 0.99337748]
[0.95454545 0.96186441 0. 0. ]
precision recall f1-score support
A 0.95 0.32 0.48 66
N 0.96 0.96 0.96 236
O 0.00 0.00 0.00 0
~ 0.00 0.00 0.00 0
accuracy 0.82 302
macro avg 0.48 0.32 0.36 302
weighted avg 0.96 0.82 0.86 302
这里的问题是——我无法清楚地推断出 A、N、O 类中的每一个的 sensitivity, specificity, pos predictivity 是什么。
【问题讨论】:
标签: machine-learning scikit-learn classification confusion-matrix