from pycm import *
y_actu = [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]
cm = ConfusionMatrix(y_actu, y_pred)
cm
pycm.ConfusionMatrix(classes: [0, 1, 2])
cm.actual_vector
[2, 0, 2, 2, 0, 1, 1, 2, 2, 0, 1, 2]
cm.predict_vector
[0, 0, 2, 1, 0, 2, 1, 0, 2, 0, 2, 2]
cm.classes
[0, 1, 2]
cm.statistic_result
{'ACC': {0: 0.83333, 1: 0.75, 2: 0.58333}, 'BM': {0: 0.77778, 1: 0.22222, 2: 0.16667}, 'DOR': {0: 'None', 1: 4.0, 2: 2.00003}, 'F1': {0: 0.75, 1: 0.4, 2: 0.54545}, 'FDR': {0: 0.4, 1: 0.5, 2: 0.4}, 'FN': {0: 0, 1: 2, 2: 3}, 'FNR': {0: 0.0, 1: 0.66667, 2: 0.5}, 'FOR': {0: 0.0, 1: 0.2, 2: 0.42857}, 'FP': {0: 2, 1: 1, 2: 2}, 'FPR': {0: 0.22222, 1: 0.11111, 2: 0.33333}, 'G': {0: 0.7746, 1: 0.40825, 2: 0.54772}, 'LR+': {0: 4.50005, 1: 3.0, 2: 1.50002}, 'LR-': {0: 0.0, 1: 0.75, 2: 0.75}, 'MCC': {0: 0.68313, 1: 0.2582, 2: 0.16903}, 'MK': {0: 0.6, 1: 0.3, 2: 0.17143}, 'N': {0: 9, 1: 9, 2: 6}, 'NPV': {0: 1.0, 1: 0.8, 2: 0.57143}, 'P': {0: 3, 1: 3, 2: 6}, 'POP': {0: 12, 1: 12, 2: 12}, 'PPV': {0: 0.6, 1: 0.5, 2: 0.6}, 'PRE': {0: 0.25, 1: 0.25, 2: 0.5}, 'TN': {0: 7, 1: 8, 2: 4}, 'TNR': {0: 0.77778, 1: 0.88889, 2: 0.66667}, 'TON': {0: 7, 1: 10, 2: 7}, 'TOP': {0: 5, 1: 2, 2: 5}, 'TP': {0: 3, 1: 1, 2: 3}, 'TPR': {0: 1.0, 1: 0.33333, 2: 0.5}}
cm.table
{0: {0: 3, 1: 0, 2: 0}, 1: {0: 0, 1: 1, 2: 2}, 2: {0: 2, 1: 1, 2: 3}}
cm.TP
{0: 3, 1: 1, 2: 3}
cm.TN
{0: 7, 1: 8, 2: 4}
cm.FP
{0: 2, 1: 1, 2: 2}
cm.FN
{0: 0, 1: 2, 2: 3}
cm.P
{0: 3, 1: 3, 2: 6}
cm.N
{0: 9, 1: 9, 2: 6}
cm.TOP
{0: 5, 1: 2, 2: 5}
cm.TON
{0: 7, 1: 10, 2: 7}
cm.POP
{0: 12, 1: 12, 2: 12}
cm.TPR
{0: 1.0, 1: 0.33333, 2: 0.5}
cm.TNR
{0: 0.77778, 1: 0.88889, 2: 0.66667}
cm.PPV
{0: 0.6, 1: 0.5, 2: 0.6}
cm.NPV
{0: 1.0, 1: 0.8, 2: 0.57143}
cm.FNR
{0: 0.0, 1: 0.66667, 2: 0.5}
cm.FPR
{0: 0.22222, 1: 0.11111, 2: 0.33333}
cm.PPV
{0: 0.6, 1: 0.5, 2: 0.6}
cm.FOR
{0: 0.0, 1: 0.2, 2: 0.42857}
cm.ACC
{0: 0.83333, 1: 0.75, 2: 0.58333}
cm.F1
{0: 0.75, 1: 0.4, 2: 0.54545}
cm.MCC
{0: 0.68313, 1: 0.2582, 2: 0.16903}
cm.BM
{0: 0.77778, 1: 0.22222, 2: 0.16667}
cm.MK
{0: 0.6, 1: 0.3, 2: 0.17143}
cm.PLR
{0: 4.50005, 1: 3.0, 2: 1.50002}
cm.NLR
{0: 0.0, 1: 0.75, 2: 0.75}
cm.DOR
{0: 'None', 1: 4.0, 2: 2.00003}
cm.PRE
{0: 0.25, 1: 0.25, 2: 0.5}
cm.G
{0: 0.7746, 1: 0.40825, 2: 0.54772}
print(cm)
Predict 0 1 2 Actual 0 3 0 0 1 0 1 2 2 2 1 3 Classes 0 1 2 ACC(accuracy) 0.83333 0.75 0.58333 BM(Informedness or Bookmaker Informedness) 0.77778 0.22222 0.16667 DOR(Diagnostic odds ratio) None 4.0 2.00003 F1(F1 Score - harmonic mean of precision and sensitivity) 0.75 0.4 0.54545 FDR(false discovery rate) 0.4 0.5 0.4 FN(false negative/miss/Type II 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 I 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 LR+(Positive likelihood ratio) 4.50005 3.0 1.50002 LR-(Negative likelihood ratio) 0.0 0.75 0.75 MCC(Matthews correlation coefficient) 0.68313 0.2582 0.16903 MK(Markedness) 0.6 0.3 0.17143 N(Condition negative) 9 9 6 NPV(negative predictive value) 1.0 0.8 0.57143 P(Condition positive) 3 3 6 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 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
cm.matrix()
Predict 0 1 2 Actual 0 3 0 0 1 0 1 2 2 2 1 3
cm.normalized_matrix()
Predict 0 1 2 Actual 0 1.0 0.0 0.0 1 0.0 0.33333 0.66667 2 0.33333 0.16667 0.5
cm.params()
Classes 0 1 2 ACC(accuracy) 0.83333 0.75 0.58333 BM(Informedness or Bookmaker Informedness) 0.77778 0.22222 0.16667 DOR(Diagnostic odds ratio) None 4.0 2.00003 F1(F1 Score - harmonic mean of precision and sensitivity) 0.75 0.4 0.54545 FDR(false discovery rate) 0.4 0.5 0.4 FN(false negative/miss/Type II 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 I 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 LR+(Positive likelihood ratio) 4.50005 3.0 1.50002 LR-(Negative likelihood ratio) 0.0 0.75 0.75 MCC(Matthews correlation coefficient) 0.68313 0.2582 0.16903 MK(Markedness) 0.6 0.3 0.17143 N(Condition negative) 9 9 6 NPV(negative predictive value) 1.0 0.8 0.57143 P(Condition positive) 3 3 6 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 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
cm2=ConfusionMatrix(y_actu, 2)
--------------------------------------------------------------------------- pycmError Traceback (most recent call last) <ipython-input-41-572bf15e689d> in <module>() ----> 1 cm2=ConfusionMatrix(y_actu, 2) ~\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pycm\pycm.py in __init__(self, actual_vector, predict_vector) 11 def __init__(self,actual_vector,predict_vector): 12 if not isinstance(actual_vector,list) or not isinstance(predict_vector,list): ---> 13 raise pycmError("Input Vectors Must Be List") 14 if len(actual_vector)!=len(predict_vector): 15 raise pycmError("Input Vectors Must Be The Same Length") pycmError: Input Vectors Must Be List
cm3=ConfusionMatrix(y_actu, [1,2,3])
--------------------------------------------------------------------------- pycmError Traceback (most recent call last) <ipython-input-42-fe0a030b981a> in <module>() ----> 1 cm3=ConfusionMatrix(y_actu, [1,2,3]) ~\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pycm\pycm.py in __init__(self, actual_vector, predict_vector) 13 raise pycmError("Input Vectors Must Be List") 14 if len(actual_vector)!=len(predict_vector): ---> 15 raise pycmError("Input Vectors Must Be The Same Length") 16 matrix_param=matrix_params_calc(actual_vector,predict_vector) 17 self.actual_vector=actual_vector pycmError: Input Vectors Must Be The Same Length