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([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.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.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}
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 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 NPV(negative predictive value) 1.0 0.8 0.57143 PPV(precision or positive predictive value) 0.6 0.5 0.6 TN(true negative/correct rejection) 7 8 4 TNR(specificity or true negative rate) 0.77778 0.88889 0.66667 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-28-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) 8 def __init__(self,actual_vector,predict_vector): 9 if not isinstance(actual_vector,list) or not isinstance(predict_vector,list): ---> 10 raise pycmError("Input Vectors Must Be List") 11 if len(actual_vector)!=len(predict_vector): 12 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-29-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) 10 raise pycmError("Input Vectors Must Be List") 11 if len(actual_vector)!=len(predict_vector): ---> 12 raise pycmError("Input Vectors Must Be The Same Length") 13 matrix_param=matrix_params_calc(actual_vector,predict_vector) 14 self.actual_vector=actual_vector pycmError: Input Vectors Must Be The Same Length