from pycm import ConfusionMatrix
y_test = [2, 0, 2, 2, 0, 1, 1, 2, 2, 0, 1, 2]
y_pred = [0, 0, 2, 1, 0, 2, 1, 0, 2, 0, 2, 2]
cm1=ConfusionMatrix(y_test, y_pred)
cm1
pycm.ConfusionMatrix(classes: [0, 1, 2])
print(cm1)
Predict 0 1 2 Actual 0 3 0 0 1 0 1 2 2 2 1 3 Overall Statistics : 95% CI (0.30439,0.86228) AUNP 0.66667 AUNU 0.69444 Bennett S 0.375 CBA 0.47778 Chi-Squared 6.6 Chi-Squared DF 4 Conditional Entropy 0.95915 Cramer V 0.5244 Cross Entropy 1.59352 Gwet AC1 0.38931 Hamming Loss 0.41667 Joint Entropy 2.45915 KL Divergence 0.09352 Kappa 0.35484 Kappa 95% CI (-0.07708,0.78675) Kappa No Prevalence 0.16667 Kappa Standard Error 0.22036 Kappa Unbiased 0.34426 Lambda A 0.16667 Lambda B 0.42857 Mutual Information 0.52421 NIR 0.5 Overall ACC 0.58333 Overall CEN 0.46381 Overall J (1.225,0.40833) Overall MCC 0.36667 Overall MCEN 0.51894 Overall RACC 0.35417 Overall RACCU 0.36458 P-Value 0.38721 PPV Macro 0.56667 PPV Micro 0.58333 Phi-Squared 0.55 RCI 0.34947 RR 4.0 Reference Entropy 1.5 Response Entropy 1.48336 SOA1(Landis & Koch) Fair SOA2(Fleiss) Poor SOA3(Altman) Fair SOA4(Cicchetti) Poor Scott PI 0.34426 Standard Error 0.14232 TPR Macro 0.61111 TPR Micro 0.58333 Zero-one Loss 5 Class Statistics : Classes 0 1 2 ACC(Accuracy) 0.83333 0.75 0.58333 AUC(Area under the roc curve) 0.88889 0.61111 0.58333 AUCI(Auc value interpretation) Very Good Fair Poor BM(Informedness or bookmaker informedness) 0.77778 0.22222 0.16667 CEN(Confusion entropy) 0.25 0.49658 0.60442 DOR(Diagnostic odds ratio) None 4.0 2.0 DP(Discriminant power) None 0.33193 0.16597 DPI(Discriminant power interpretation) None Poor Poor ERR(Error rate) 0.16667 0.25 0.41667 F0.5(F0.5 score) 0.65217 0.45455 0.57692 F1(F1 score - harmonic mean of precision and sensitivity) 0.75 0.4 0.54545 F2(F2 score) 0.88235 0.35714 0.51724 FDR(False discovery rate) 0.4 0.5 0.4 FN(False negative/miss/type 2 error) 0 2 3 FNR(Miss rate or false negative rate) 0.0 0.66667 0.5 FOR(False omission rate) 0.0 0.2 0.42857 FP(False positive/type 1 error/false alarm) 2 1 2 FPR(Fall-out or false positive rate) 0.22222 0.11111 0.33333 G(G-measure geometric mean of precision and sensitivity) 0.7746 0.40825 0.54772 GI(Gini index) 0.77778 0.22222 0.16667 IS(Information score) 1.26303 1.0 0.26303 J(Jaccard index) 0.6 0.25 0.375 MCC(Matthews correlation coefficient) 0.68313 0.2582 0.16903 MCEN(Modified confusion entropy) 0.26439 0.5 0.6875 MK(Markedness) 0.6 0.3 0.17143 N(Condition negative) 9 9 6 NLR(Negative likelihood ratio) 0.0 0.75 0.75 NPV(Negative predictive value) 1.0 0.8 0.57143 P(Condition positive or support) 3 3 6 PLR(Positive likelihood ratio) 4.5 3.0 1.5 PLRI(Positive likelihood ratio interpretation) Poor Poor Poor POP(Population) 12 12 12 PPV(Precision or positive predictive value) 0.6 0.5 0.6 PRE(Prevalence) 0.25 0.25 0.5 RACC(Random accuracy) 0.10417 0.04167 0.20833 RACCU(Random accuracy unbiased) 0.11111 0.0434 0.21007 TN(True negative/correct rejection) 7 8 4 TNR(Specificity or true negative rate) 0.77778 0.88889 0.66667 TON(Test outcome negative) 7 10 7 TOP(Test outcome positive) 5 2 5 TP(True positive/hit) 3 1 3 TPR(Sensitivity, recall, hit rate, or true positive rate) 1.0 0.33333 0.5 Y(Youden index) 0.77778 0.22222 0.16667 dInd(Distance index) 0.22222 0.67586 0.60093 sInd(Similarity index) 0.84287 0.52209 0.57508
from random import randint
weights = [randint(1,10) for i in range(len(y_test))]
weights[2]*=9
cm2=ConfusionMatrix(y_test, y_pred, sample_weight = weights)
cm2
pycm.ConfusionMatrix(classes: [0, 1, 2])
print(cm2)
Predict 0 1 2 Actual 0 13 0 0 1 0 4 11 2 11 6 74 Overall Statistics : 95% CI (0.68849,0.84092) AUNP 0.72284 AUNU 0.75426 Bennett S 0.64706 CBA 0.54051 Chi-Squared 64.99179 Chi-Squared DF 4 Conditional Entropy 0.77055 Cramer V 0.52257 Cross Entropy 1.07391 Gwet AC1 0.70255 Hamming Loss 0.23529 Joint Entropy 1.79211 KL Divergence 0.05236 Kappa 0.44131 Kappa 95% CI (0.26035,0.62228) Kappa No Prevalence 0.52941 Kappa Standard Error 0.09233 Kappa Unbiased 0.43702 Lambda A 0.07143 Lambda B 0.38235 Mutual Information 0.34228 NIR 0.76471 Overall ACC 0.76471 Overall CEN 0.34008 Overall J (1.45763,0.48588) Overall MCC 0.44913 Overall MCEN 0.43775 Overall RACC 0.57884 Overall RACCU 0.58206 P-Value 0.55048 PPV Macro 0.60408 PPV Micro 0.76471 Phi-Squared 0.54615 RCI 0.33505 RR 39.66667 Reference Entropy 1.02155 Response Entropy 1.11283 SOA1(Landis & Koch) Moderate SOA2(Fleiss) Intermediate to Good SOA3(Altman) Moderate SOA4(Cicchetti) Fair Scott PI 0.43702 Standard Error 0.03888 TPR Macro 0.69328 TPR Micro 0.76471 Zero-one Loss 28 Class Statistics : Classes 0 1 2 ACC(Accuracy) 0.90756 0.85714 0.76471 AUC(Area under the roc curve) 0.94811 0.60449 0.71016 AUCI(Auc value interpretation) Excellent Fair Good BM(Informedness or bookmaker informedness) 0.89623 0.20897 0.42033 CEN(Confusion entropy) 0.26014 0.50764 0.33309 DOR(Diagnostic odds ratio) None 5.93939 6.72727 DP(Discriminant power) None 0.42659 0.45641 DPI(Discriminant power interpretation) None Poor Poor ERR(Error rate) 0.09244 0.14286 0.23529 F0.5(F0.5 score) 0.59633 0.36364 0.85847 F1(F1 score - harmonic mean of precision and sensitivity) 0.7027 0.32 0.84091 F2(F2 score) 0.85526 0.28571 0.82405 FDR(False discovery rate) 0.45833 0.6 0.12941 FN(False negative/miss/type 2 error) 0 11 17 FNR(Miss rate or false negative rate) 0.0 0.73333 0.18681 FOR(False omission rate) 0.0 0.10092 0.5 FP(False positive/type 1 error/false alarm) 11 6 11 FPR(Fall-out or false positive rate) 0.10377 0.05769 0.39286 G(G-measure geometric mean of precision and sensitivity) 0.73598 0.3266 0.8414 GI(Gini index) 0.89623 0.20897 0.42033 IS(Information score) 2.30986 1.666 0.18709 J(Jaccard index) 0.54167 0.19048 0.72549 MCC(Matthews correlation coefficient) 0.69675 0.25 0.39468 MCEN(Modified confusion entropy) 0.25793 0.50252 0.46672 MK(Markedness) 0.54167 0.29908 0.37059 N(Condition negative) 106 104 28 NLR(Negative likelihood ratio) 0.0 0.77823 0.30769 NPV(Negative predictive value) 1.0 0.89908 0.5 P(Condition positive or support) 13 15 91 PLR(Positive likelihood ratio) 9.63636 4.62222 2.06993 PLRI(Positive likelihood ratio interpretation) Fair Poor Poor POP(Population) 119 119 119 PPV(Precision or positive predictive value) 0.54167 0.4 0.87059 PRE(Prevalence) 0.10924 0.12605 0.76471 RACC(Random accuracy) 0.02203 0.01059 0.54622 RACCU(Random accuracy unbiased) 0.02417 0.01103 0.54685 TN(True negative/correct rejection) 95 98 17 TNR(Specificity or true negative rate) 0.89623 0.94231 0.60714 TON(Test outcome negative) 95 109 34 TOP(Test outcome positive) 24 10 85 TP(True positive/hit) 13 4 74 TPR(Sensitivity, recall, hit rate, or true positive rate) 1.0 0.26667 0.81319 Y(Youden index) 0.89623 0.20897 0.42033 dInd(Distance index) 0.10377 0.7356 0.43501 sInd(Similarity index) 0.92662 0.47985 0.6924