我必须计算精确和召回的大学项目,以衡量质量的分类输出(与学习)。说这就是我的结果:
y_true = 0,1,2,1,1
y_pred = 0,2,1,2,1
混淆矩阵:
1 0 0
0 1 2
0 1 0
我读过关于它的文章,在二进制设置下,这个定义对我来说是有意义的,但是有了3个标签,我发现很难解释精确/回忆。
如果我使用sklearn.emeics.精准/召回分数,那么两者都是0.4 (平均=微)。
至于精度,这有点道理,因为五分之二的分类是正确的。但我在解释召回的0.4结果时遇到了问题。
发布于 2018-05-23 09:43:43
from sklearn.metrics import recall_score
如果然后调用recall_score.__dir__ (或直接读取文档这里),您将看到
召回率为
tp / (tp + fn),其中tp为真阳性数,fn为假阴性数。
如果你深入到他们定义micro的地方,上面写着
'micro':通过计算总真阳性、假阴性和假阳性来全局计算度量
在这里,真正的正数是2 (对角线上的项之和,也称为跟踪),而假负数加假阳性之和(非对角线项)是3。
作为2/5=.4,召回(使用average的micro参数)实际上是.4。
注意,使用micro,精确性和召回是相同的。实际上,以下内容不返回任何内容:
from numpy import random
from sklearn.metrics import recall_score, precision_score
for i in range(100):
y_pred = random.randint(0, 3, 5)
y_true = random.randint(0, 3, 5)
if recall_score(y_pred, y_true, average='micro') != precision_score(y_pred, y_true, average='micro'):
print(i)发布于 2018-05-23 11:29:33
sklearn.metrics.classification_报告为所有类提供精确性和召回功能,并提供F分数和支持.这可能被证明是有帮助的,在你的情况下,3类。
发布于 2018-06-04 19:25:03
您还可以使用PyCM库进行多类混淆矩阵分析。
你的问题:
>>> print(cm)
Predict 0 1 2
Actual
0 1 0 0
1 0 1 2
2 0 1 0
Overall Statistics :
95% CI (-0.02941,0.82941)
Bennett_S 0.1
Chi-Squared 6.66667
Chi-Squared DF 4
Conditional Entropy 0.55098
Cramer_V 0.8165
Cross Entropy 1.52193
Gwet_AC1 0.13043
Joint Entropy 1.92193
KL Divergence 0.15098
Kappa 0.0625
Kappa 95% CI (-0.60846,0.73346)
Kappa No Prevalence -0.2
Kappa Standard Error 0.34233
Kappa Unbiased 0.03226
Lambda A 0.5
Lambda B 0.66667
Mutual Information 0.97095
Overall_ACC 0.4
Overall_RACC 0.36
Overall_RACCU 0.38
PPV_Macro 0.5
PPV_Micro 0.4
Phi-Squared 1.33333
Reference Entropy 1.37095
Response Entropy 1.52193
Scott_PI 0.03226
Standard Error 0.21909
Strength_Of_Agreement(Altman) Poor
Strength_Of_Agreement(Cicchetti) Poor
Strength_Of_Agreement(Fleiss) Poor
Strength_Of_Agreement(Landis and Koch) Slight
TPR_Macro 0.44444
TPR_Micro 0.4
Class Statistics :
Classes 0 1 2
ACC(Accuracy) 1.0 0.4 0.4
BM(Informedness or bookmaker informedness) 1.0 -0.16667 -0.5
DOR(Diagnostic odds ratio) None 0.5 0.0
ERR(Error rate) 0.0 0.6 0.6
F0.5(F0.5 score) 1.0 0.45455 0.0
F1(F1 score - harmonic mean of precision and sensitivity) 1.0 0.4 0.0
F2(F2 score) 1.0 0.35714 0.0
FDR(False discovery rate) 0.0 0.5 1.0
FN(False negative/miss/type 2 error) 0 2 1
FNR(Miss rate or false negative rate) 0.0 0.66667 1.0
FOR(False omission rate) 0.0 0.66667 0.33333
FP(False positive/type 1 error/false alarm) 0 1 2
FPR(Fall-out or false positive rate) 0.0 0.5 0.5
G(G-measure geometric mean of precision and sensitivity) 1.0 0.40825 0.0
LR+(Positive likelihood ratio) None 0.66667 0.0
LR-(Negative likelihood ratio) 0.0 1.33333 2.0
MCC(Matthews correlation coefficient) 1.0 -0.16667 -0.40825
MK(Markedness) 1.0 -0.16667 -0.33333
N(Condition negative) 4 2 4
NPV(Negative predictive value) 1.0 0.33333 0.66667
P(Condition positive) 1 3 1
POP(Population) 5 5 5
PPV(Precision or positive predictive value) 1.0 0.5 0.0
PRE(Prevalence) 0.2 0.6 0.2
RACC(Random accuracy) 0.04 0.24 0.08
RACCU(Random accuracy unbiased) 0.04 0.25 0.09
TN(True negative/correct rejection) 4 1 2
TNR(Specificity or true negative rate) 1.0 0.5 0.5
TON(Test outcome negative) 4 3 3
TOP(Test outcome positive) 1 2 2
TP(True positive/hit) 1 1 0
TPR(Sensitivity, recall, hit rate, or true positive rate) 1.0 0.33333 0.0https://datascience.stackexchange.com/questions/32032
复制相似问题