Multi-class confusion matrix library in Python

Overview

Table of contents

Overview

PyCM is a multi-class confusion matrix library written in Python that supports both input data vectors and direct matrix, and a proper tool for post-classification model evaluation that supports most classes and overall statistics parameters. PyCM is the swiss-army knife of confusion matrices, targeted mainly at data scientists that need a broad array of metrics for predictive models and accurate evaluation of a large variety of classifiers.

Fig1. ConfusionMatrix Block Diagram

Open Hub
PyPI Counter
Github Stars
Branch master dev
Travis
AppVeyor
Code Quality CodeFactor codebeat badge

Installation

⚠️ PyCM 2.4 is the last version to support Python 2.7 & Python 3.4

⚠️ Plotting capability requires Matplotlib (>= 3.0.0) or Seaborn (>= 0.9.1)

Source code

  • Download Version 3.0 or Latest Source
  • Run pip install -r requirements.txt or pip3 install -r requirements.txt (Need root access)
  • Run python3 setup.py install or python setup.py install (Need root access)

PyPI

Conda

Easy install

  • Run easy_install --upgrade pycm (Need root access)

MATLAB

  • Download and install MATLAB (>=8.5, 64/32 bit)
  • Download and install Python3.x (>=3.5, 64/32 bit)
    • Select Add to PATH option
    • Select Install pip option
  • Run pip install pycm or pip3 install pycm (Need root access)
  • Configure Python interpreter
>> pyversion PYTHON_EXECUTABLE_FULL_PATH

Docker

  • Run docker pull sepandhaghighi/pycm (Need root access)
  • Configuration :
    • Ubuntu 16.04
    • Python 3.6

Usage

From vector

>>> from pycm import *
>>> y_actu = [2, 0, 2, 2, 0, 1, 1, 2, 2, 0, 1, 2] # or y_actu = numpy.array([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] # or y_pred = numpy.array([0, 0, 2, 1, 0, 2, 1, 0, 2, 0, 2, 2])
>>> cm = ConfusionMatrix(actual_vector=y_actu, predict_vector=y_pred) # Create CM From Data
>>> cm.classes
[0, 1, 2]
>>> cm.table
{0: {0: 3, 1: 0, 2: 0}, 1: {0: 0, 1: 1, 2: 2}, 2: {0: 2, 1: 1, 2: 3}}
>>> print(cm)
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)
ACC Macro                                                         0.72222
ARI                                                               0.09206
AUNP                                                              0.66667
AUNU                                                              0.69444
Bangdiwala B                                                      0.37255
Bennett S                                                         0.375
CBA                                                               0.47778
CSI                                                               0.17778
Chi-Squared                                                       6.6
Chi-Squared DF                                                    4
Conditional Entropy                                               0.95915
Cramer V                                                          0.5244
Cross Entropy                                                     1.59352
F1 Macro                                                          0.56515
F1 Micro                                                          0.58333
FNR Macro                                                         0.38889
FNR Micro                                                         0.41667
FPR Macro                                                         0.22222
FPR Micro                                                         0.20833
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
Krippendorff Alpha                                                0.37158
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
Pearson C                                                         0.59568
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
SOA5(Cramer)                                                      Relatively Strong
SOA6(Matthews)                                                    Weak
Scott PI                                                          0.34426
Standard Error                                                    0.14232
TNR Macro                                                         0.77778
TNR Micro                                                         0.79167
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       
AGF(Adjusted F-score)                                             0.9136        0.53995       0.5516        
AGM(Adjusted geometric mean)                                      0.83729       0.692         0.60712       
AM(Difference between automatic and manual classification)        2             -1            -1            
AUC(Area under the ROC curve)                                     0.88889       0.61111       0.58333       
AUCI(AUC value interpretation)                                    Very Good     Fair          Poor          
AUPR(Area under the PR curve)                                     0.8           0.41667       0.55          
BCD(Bray-Curtis dissimilarity)                                    0.08333       0.04167       0.04167       
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       
GM(G-mean geometric mean of specificity and sensitivity)          0.88192       0.54433       0.57735       
IBA(Index of balanced accuracy)                                   0.95062       0.13169       0.27778       
ICSI(Individual classification success index)                     0.6           -0.16667      0.1           
IS(Information score)                                             1.26303       1.0           0.26303       
J(Jaccard index)                                                  0.6           0.25          0.375         
LS(Lift score)                                                    2.4           2.0           1.2           
MCC(Matthews correlation coefficient)                             0.68313       0.2582        0.16903       
MCCI(Matthews correlation coefficient interpretation)             Moderate      Negligible    Negligible    
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          
NLRI(Negative likelihood ratio interpretation)                    Good          Negligible    Negligible    
NPV(Negative predictive value)                                    1.0           0.8           0.57143       
OC(Overlap coefficient)                                           1.0           0.5           0.6           
OOC(Otsuka-Ochiai coefficient)                                    0.7746        0.40825       0.54772       
OP(Optimized precision)                                           0.70833       0.29545       0.44048       
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           
Q(Yule Q - coefficient of colligation)                            None          0.6           0.33333       
QI(Yule Q interpretation)                                         None          Moderate      Weak          
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

>>> cm.print_matrix()
Predict          0    1    2    
Actual
0                3    0    0    

1                0    1    2    

2                2    1    3    

>>> cm.print_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.print_matrix(one_vs_all=True,class_name=0)   # One-Vs-All, new in version 1.4
Predict          0    ~    
Actual
0                3    0    

~                2    7    

Direct CM

>>> from pycm import *
>>> cm2 = ConfusionMatrix(matrix={"Class1": {"Class1": 1, "Class2":2}, "Class2": {"Class1": 0, "Class2": 5}}) # Create CM Directly
>>> cm2
pycm.ConfusionMatrix(classes: ['Class1', 'Class2'])
>>> print(cm2)
Predict      Class1       Class2       
Actual
Class1       1            2            

Class2       0            5            





Overall Statistics : 

95% CI                                                            (0.44994,1.05006)
ACC Macro                                                         0.75
ARI                                                               0.17241
AUNP                                                              0.66667
AUNU                                                              0.66667
Bangdiwala B                                                      0.68421
Bennett S                                                         0.5
CBA                                                               0.52381
CSI                                                               0.52381
Chi-Squared                                                       1.90476
Chi-Squared DF                                                    1
Conditional Entropy                                               0.34436
Cramer V                                                          0.48795
Cross Entropy                                                     1.2454
F1 Macro                                                          0.66667
F1 Micro                                                          0.75
FNR Macro                                                         0.33333
FNR Micro                                                         0.25
FPR Macro                                                         0.33333
FPR Micro                                                         0.25
Gwet AC1                                                          0.6
Hamming Loss                                                      0.25
Joint Entropy                                                     1.29879
KL Divergence                                                     0.29097
Kappa                                                             0.38462
Kappa 95% CI                                                      (-0.354,1.12323)
Kappa No Prevalence                                               0.5
Kappa Standard Error                                              0.37684
Kappa Unbiased                                                    0.33333
Krippendorff Alpha                                                0.375
Lambda A                                                          0.33333
Lambda B                                                          0.0
Mutual Information                                                0.1992
NIR                                                               0.625
Overall ACC                                                       0.75
Overall CEN                                                       0.44812
Overall J                                                         (1.04762,0.52381)
Overall MCC                                                       0.48795
Overall MCEN                                                      0.29904
Overall RACC                                                      0.59375
Overall RACCU                                                     0.625
P-Value                                                           0.36974
PPV Macro                                                         0.85714
PPV Micro                                                         0.75
Pearson C                                                         0.43853
Phi-Squared                                                       0.2381
RCI                                                               0.20871
RR                                                                4.0
Reference Entropy                                                 0.95443
Response Entropy                                                  0.54356
SOA1(Landis & Koch)                                               Fair
SOA2(Fleiss)                                                      Poor
SOA3(Altman)                                                      Fair
SOA4(Cicchetti)                                                   Poor
SOA5(Cramer)                                                      Relatively Strong
SOA6(Matthews)                                                    Weak
Scott PI                                                          0.33333
Standard Error                                                    0.15309
TNR Macro                                                         0.66667
TNR Micro                                                         0.75
TPR Macro                                                         0.66667
TPR Micro                                                         0.75
Zero-one Loss                                                     2

Class Statistics :

Classes                                                           Class1        Class2        
ACC(Accuracy)                                                     0.75          0.75          
AGF(Adjusted F-score)                                             0.53979       0.81325       
AGM(Adjusted geometric mean)                                      0.73991       0.5108        
AM(Difference between automatic and manual classification)        -2            2             
AUC(Area under the ROC curve)                                     0.66667       0.66667       
AUCI(AUC value interpretation)                                    Fair          Fair          
AUPR(Area under the PR curve)                                     0.66667       0.85714       
BCD(Bray-Curtis dissimilarity)                                    0.125         0.125         
BM(Informedness or bookmaker informedness)                        0.33333       0.33333       
CEN(Confusion entropy)                                            0.5           0.43083       
DOR(Diagnostic odds ratio)                                        None          None          
DP(Discriminant power)                                            None          None          
DPI(Discriminant power interpretation)                            None          None          
ERR(Error rate)                                                   0.25          0.25          
F0.5(F0.5 score)                                                  0.71429       0.75758       
F1(F1 score - harmonic mean of precision and sensitivity)         0.5           0.83333       
F2(F2 score)                                                      0.38462       0.92593       
FDR(False discovery rate)                                         0.0           0.28571       
FN(False negative/miss/type 2 error)                              2             0             
FNR(Miss rate or false negative rate)                             0.66667       0.0           
FOR(False omission rate)                                          0.28571       0.0           
FP(False positive/type 1 error/false alarm)                       0             2             
FPR(Fall-out or false positive rate)                              0.0           0.66667       
G(G-measure geometric mean of precision and sensitivity)          0.57735       0.84515       
GI(Gini index)                                                    0.33333       0.33333       
GM(G-mean geometric mean of specificity and sensitivity)          0.57735       0.57735       
IBA(Index of balanced accuracy)                                   0.11111       0.55556       
ICSI(Individual classification success index)                     0.33333       0.71429       
IS(Information score)                                             1.41504       0.19265       
J(Jaccard index)                                                  0.33333       0.71429       
LS(Lift score)                                                    2.66667       1.14286       
MCC(Matthews correlation coefficient)                             0.48795       0.48795       
MCCI(Matthews correlation coefficient interpretation)             Weak          Weak          
MCEN(Modified confusion entropy)                                  0.38998       0.51639       
MK(Markedness)                                                    0.71429       0.71429       
N(Condition negative)                                             5             3             
NLR(Negative likelihood ratio)                                    0.66667       0.0           
NLRI(Negative likelihood ratio interpretation)                    Negligible    Good          
NPV(Negative predictive value)                                    0.71429       1.0           
OC(Overlap coefficient)                                           1.0           1.0           
OOC(Otsuka-Ochiai coefficient)                                    0.57735       0.84515       
OP(Optimized precision)                                           0.25          0.25          
P(Condition positive or support)                                  3             5             
PLR(Positive likelihood ratio)                                    None          1.5           
PLRI(Positive likelihood ratio interpretation)                    None          Poor          
POP(Population)                                                   8             8             
PPV(Precision or positive predictive value)                       1.0           0.71429       
PRE(Prevalence)                                                   0.375         0.625         
Q(Yule Q - coefficient of colligation)                            None          None          
QI(Yule Q interpretation)                                         None          None          
RACC(Random accuracy)                                             0.04688       0.54688       
RACCU(Random accuracy unbiased)                                   0.0625        0.5625        
TN(True negative/correct rejection)                               5             1             
TNR(Specificity or true negative rate)                            1.0           0.33333       
TON(Test outcome negative)                                        7             1             
TOP(Test outcome positive)                                        1             7             
TP(True positive/hit)                                             1             5             
TPR(Sensitivity, recall, hit rate, or true positive rate)         0.33333       1.0           
Y(Youden index)                                                   0.33333       0.33333       
dInd(Distance index)                                              0.66667       0.66667       
sInd(Similarity index)                                            0.5286        0.5286
   
>>> cm2.stat(summary=True)
Overall Statistics : 

ACC Macro                                                         0.75
F1 Macro                                                          0.66667
FPR Macro                                                         0.33333
Kappa                                                             0.38462
Overall ACC                                                       0.75
PPV Macro                                                         0.85714
SOA1(Landis & Koch)                                               Fair
TPR Macro                                                         0.66667
Zero-one Loss                                                     2

Class Statistics :

Classes                                                           Class1        Class2        
ACC(Accuracy)                                                     0.75          0.75          
AUC(Area under the ROC curve)                                     0.66667       0.66667       
AUCI(AUC value interpretation)                                    Fair          Fair          
F1(F1 score - harmonic mean of precision and sensitivity)         0.5           0.83333       
FN(False negative/miss/type 2 error)                              2             0             
FP(False positive/type 1 error/false alarm)                       0             2             
FPR(Fall-out or false positive rate)                              0.0           0.66667       
N(Condition negative)                                             5             3             
P(Condition positive or support)                                  3             5             
POP(Population)                                                   8             8             
PPV(Precision or positive predictive value)                       1.0           0.71429       
TN(True negative/correct rejection)                               5             1             
TON(Test outcome negative)                                        7             1             
TOP(Test outcome positive)                                        1             7             
TP(True positive/hit)                                             1             5             
TPR(Sensitivity, recall, hit rate, or true positive rate)         0.33333       1.0 
                               
>>> cm3 = ConfusionMatrix(matrix={"Class1": {"Class1": 1, "Class2":0}, "Class2": {"Class1": 2, "Class2": 5}},transpose=True) # Transpose Matrix      
>>> cm3.print_matrix()
Predict          Class1    Class2    
Actual
Class1           1         2         

Class2           0         5         
  • matrix() and normalized_matrix() renamed to print_matrix() and print_normalized_matrix() in version 1.5

Activation threshold

threshold is added in version 0.9 for real value prediction.

For more information visit Example3

Load from file

file is added in version 0.9.5 in order to load saved confusion matrix with .obj format generated by save_obj method.

For more information visit Example4

Sample weights

sample_weight is added in version 1.2

For more information visit Example5

Transpose

transpose is added in version 1.2 in order to transpose input matrix (only in Direct CM mode)

Relabel

relabel method is added in version 1.5 in order to change ConfusionMatrix classnames.

>>> cm.relabel(mapping={0:"L1",1:"L2",2:"L3"})
>>> cm
pycm.ConfusionMatrix(classes: ['L1', 'L2', 'L3'])

Position

position method is added in version 2.8 in order to find the indexes of observations in predict_vector which made TP, TN, FP, FN.

>>> cm.position()
{0: {'FN': [], 'FP': [0, 7], 'TP': [1, 4, 9], 'TN': [2, 3, 5, 6, 8, 10, 11]}, 1: {'FN': [5, 10], 'FP': [3], 'TP': [6], 'TN': [0, 1, 2, 4, 7, 8, 9, 11]}, 2: {'FN': [0, 3, 7], 'FP': [5, 10], 'TP': [2, 8, 11], 'TN': [1, 4, 6, 9]}}

To array

to_array method is added in version 2.9 in order to returns the confusion matrix in the form of a NumPy array. This can be helpful to apply different operations over the confusion matrix for different purposes such as aggregation, normalization, and combination.

>>> cm.to_array()
array([[3, 0, 0],
       [0, 1, 2],
       [2, 1, 3]])
>>> cm.to_array(normalized=True)
array([[1.     , 0.     , 0.     ],
       [0.     , 0.33333, 0.66667],
       [0.33333, 0.16667, 0.5    ]])
>>> cm.to_array(normalized=True,one_vs_all=True, class_name="L1")
array([[1.     , 0.     ],
       [0.22222, 0.77778]])

Combine

combine method is added in version 3.0 in order to merge two confusion matrices. This option will be useful in mini-batch learning.

>>> cm_combined = cm2.combine(cm3)
>>> cm_combined.print_matrix()
Predict      Class1       Class2       
Actual
Class1       2            4            

Class2       0            10           

Plot

plot method is added in version 3.0 in order to plot a confusion matrix using Matplotlib or Seaborn.

>>> cm.plot()

>>> from matplotlib import pyplot as plt
>>> cm.plot(cmap=plt.cm.Greens,number_label=True,plot_lib="matplotlib")

>>> cm.plot(cmap=plt.cm.Reds,normalized=True,number_label=True,plot_lib="seaborn")

Online help

online_help function is added in version 1.1 in order to open each statistics definition in web browser

>>> from pycm import online_help
>>> online_help("J")
>>> online_help("SOA1(Landis & Koch)")
>>> online_help(2)
  • List of items are available by calling online_help() (without argument)
  • If PyCM website is not available, set alt_link = True (new in version 2.4)

Parameter recommender

This option has been added in version 1.9 to recommend the most related parameters considering the characteristics of the input dataset. The suggested parameters are selected according to some characteristics of the input such as being balance/imbalance and binary/multi-class. All suggestions can be categorized into three main groups: imbalanced dataset, binary classification for a balanced dataset, and multi-class classification for a balanced dataset. The recommendation lists have been gathered according to the respective paper of each parameter and the capabilities which had been claimed by the paper.

>>> cm.imbalance
False
>>> cm.binary
False
>>> cm.recommended_list
['MCC', 'TPR Micro', 'ACC', 'PPV Macro', 'BCD', 'Overall MCC', 'Hamming Loss', 'TPR Macro', 'Zero-one Loss', 'ERR', 'PPV Micro', 'Overall ACC']

Compare

In version 2.0, a method for comparing several confusion matrices is introduced. This option is a combination of several overall and class-based benchmarks. Each of the benchmarks evaluates the performance of the classification algorithm from good to poor and give them a numeric score. The score of good and poor performances are 1 and 0, respectively.

After that, two scores are calculated for each confusion matrices, overall and class-based. The overall score is the average of the score of six overall benchmarks which are Landis & Koch, Fleiss, Altman, Cicchetti, Cramer, and Matthews. In the same manner, the class-based score is the average of the score of six class-based benchmarks which are Positive Likelihood Ratio Interpretation, Negative Likelihood Ratio Interpretation, Discriminant Power Interpretation, AUC value Interpretation, Matthews Correlation Coefficient Interpretation and Yule's Q Interpretation. It should be noticed that if one of the benchmarks returns none for one of the classes, that benchmarks will be eliminated in total averaging. If the user sets weights for the classes, the averaging over the value of class-based benchmark scores will transform to a weighted average.

If the user sets the value of by_class boolean input True, the best confusion matrix is the one with the maximum class-based score. Otherwise, if a confusion matrix obtains the maximum of both overall and class-based scores, that will be reported as the best confusion matrix, but in any other case, the compared object doesn’t select the best confusion matrix.

>>> cm2 = ConfusionMatrix(matrix={0:{0:2,1:50,2:6},1:{0:5,1:50,2:3},2:{0:1,1:7,2:50}})
>>> cm3 = ConfusionMatrix(matrix={0:{0:50,1:2,2:6},1:{0:50,1:5,2:3},2:{0:1,1:55,2:2}})
>>> cp = Compare({"cm2":cm2,"cm3":cm3})
>>> print(cp)
Best : cm2

Rank  Name   Class-Score    Overall-Score
1     cm2    9.05           2.55
2     cm3    6.05           1.98333

>>> cp.best
pycm.ConfusionMatrix(classes: [0, 1, 2])
>>> cp.sorted
['cm2', 'cm3']
>>> cp.best_name
'cm2'

Acceptable data types

ConfusionMatrix

  1. actual_vector : python list or numpy array of any stringable objects
  2. predict_vector : python list or numpy array of any stringable objects
  3. matrix : dict
  4. digit: int
  5. threshold : FunctionType (function or lambda)
  6. file : File object
  7. sample_weight : python list or numpy array of numbers
  8. transpose : bool
  • Run help(ConfusionMatrix) for ConfusionMatrix object details

Compare

  1. cm_dict : python dict of ConfusionMatrix object (str : ConfusionMatrix)
  2. by_class : bool
  3. weight : python dict of class weights (class_name : float)
  4. digit: int
  • Run help(Compare) for Compare object details

For more information visit here

Try PyCM in your browser!

PyCM can be used online in interactive Jupyter Notebooks via the Binder service! Try it out now! :

Binder

  • Check Examples in Document folder

Issues & bug reports

Just fill an issue and describe it. We'll check it ASAP! or send an email to [email protected].

  • Please complete the issue template

Outputs

  1. HTML
  2. CSV
  3. PyCM
  4. OBJ
  5. COMP

Dependencies

master dev
Requirements Status Requirements Status

References

1- J. R. Landis, G. G. Koch, “The measurement of observer agreement for categorical data. Biometrics,” in International Biometric Society, pp. 159–174, 1977.
2- D. M. W. Powers, “Evaluation: from precision, recall and f-measure to roc, informedness, markedness & correlation,” in Journal of Machine Learning Technologies, pp.37-63, 2011.
3- C. Sammut, G. Webb, “Encyclopedia of Machine Learning” in Springer, 2011.
4- J. L. Fleiss, “Measuring nominal scale agreement among many raters,” in Psychological Bulletin, pp. 378-382, 1971.
5- D.G. Altman, “Practical Statistics for Medical Research,” in Chapman and Hall, 1990.
6- K. L. Gwet, “Computing inter-rater reliability and its variance in the presence of high agreement,” in The British Journal of Mathematical and Statistical Psychology, pp. 29–48, 2008.”
7- W. A. Scott, “Reliability of content analysis: The case of nominal scaling,” in Public Opinion Quarterly, pp. 321–325, 1955.
8- E. M. Bennett, R. Alpert, and A. C. Goldstein, “Communication through limited response questioning,” in The Public Opinion Quarterly, pp. 303–308, 1954.
9- D. V. Cicchetti, "Guidelines, criteria, and rules of thumb for evaluating normed and standardized assessment instruments in psychology," in Psychological Assessment, pp. 284–290, 1994.
10- R.B. Davies, "Algorithm AS155: The Distributions of a Linear Combination of χ2 Random Variables," in Journal of the Royal Statistical Society, pp. 323–333, 1980.
11- S. Kullback, R. A. Leibler "On information and sufficiency," in Annals of Mathematical Statistics, pp. 79–86, 1951.
12- L. A. Goodman, W. H. Kruskal, "Measures of Association for Cross Classifications, IV: Simplification of Asymptotic Variances," in Journal of the American Statistical Association, pp. 415–421, 1972.
13- L. A. Goodman, W. H. Kruskal, "Measures of Association for Cross Classifications III: Approximate Sampling Theory," in Journal of the American Statistical Association, pp. 310–364, 1963.
14- T. Byrt, J. Bishop and J. B. Carlin, “Bias, prevalence, and kappa,” in Journal of Clinical Epidemiology pp. 423-429, 1993.
15- M. Shepperd, D. Bowes, and T. Hall, “Researcher Bias: The Use of Machine Learning in Software Defect Prediction,” in IEEE Transactions on Software Engineering, pp. 603-616, 2014.
16- X. Deng, Q. Liu, Y. Deng, and S. Mahadevan, “An improved method to construct basic probability assignment based on the confusion matrix for classification problem, ” in Information Sciences, pp.250-261, 2016.
17- J.-M. Wei, X.-J. Yuan, Q.-H. Hu, and S.-Q. J. E. S. w. A. Wang, "A novel measure for evaluating classifiers," in Expert Systems with Applications, pp. 3799-3809, 2010.
18- I. Kononenko and I. J. M. L. Bratko, "Information-based evaluation criterion for classifier's performance," in Machine Learning, pp. 67-80, 1991.
19- R. Delgado and J. D. Núñez-González, "Enhancing Confusion Entropy as Measure for Evaluating Classifiers," in The 13th International Conference on Soft Computing Models in Industrial and Environmental Applications, pp. 79-89, 2018: Springer.
20- J. J. C. b. Gorodkin and chemistry, "Comparing two K-category assignments by a K-category correlation coefficient," in Computational Biology and chemistry, pp. 367-374, 2004.
21- C. O. Freitas, J. M. De Carvalho, J. Oliveira, S. B. Aires, and R. Sabourin, "Confusion matrix disagreement for multiple classifiers," in Iberoamerican Congress on Pattern Recognition, pp. 387-396, 2007.
22- P. Branco, L. Torgo, and R. P. Ribeiro, "Relevance-based evaluation metrics for multi-class imbalanced domains," in Pacific-Asia Conference on Knowledge Discovery and Data Mining, pp. 698-710, 2017. Springer.
23- D. Ballabio, F. Grisoni, R. J. C. Todeschini, and I. L. Systems, "Multivariate comparison of classification performance measures," in Chemometrics and Intelligent Laboratory Systems, pp. 33-44, 2018.
24- J. J. E. Cohen and p. measurement, "A coefficient of agreement for nominal scales," in Educational and Psychological Measurement, pp. 37-46, 1960.
25- S. Siegel, "Nonparametric statistics for the behavioral sciences," in New York : McGraw-Hill, 1956.
26- H. Cramér, "Mathematical methods of statistics (PMS-9),"in Princeton university press, 2016.
27- B. W. J. B. e. B. A.-P. S. Matthews, "Comparison of the predicted and observed secondary structure of T4 phage lysozyme," in Biochimica et Biophysica Acta (BBA) - Protein Structure, pp. 442-451, 1975.
28- J. A. J. S. Swets, "The relative operating characteristic in psychology: a technique for isolating effects of response bias finds wide use in the study of perception and cognition," in American Association for the Advancement of Science, pp. 990-1000, 1973.
29- P. J. B. S. V. S. N. Jaccard, "Étude comparative de la distribution florale dans une portion des Alpes et des Jura," in Bulletin de la Société vaudoise des sciences naturelles, pp. 547-579, 1901.
30- T. M. Cover and J. A. Thomas, "Elements of information theory," in John Wiley & Sons, 2012.
31- E. S. Keeping, "Introduction to statistical inference," in Courier Corporation, 1995.
32- V. Sindhwani, P. Bhattacharya, and S. Rakshit, "Information theoretic feature crediting in multiclass support vector machines," in Proceedings of the 2001 SIAM International Conference on Data Mining, pp. 1-18, 2001.
33- M. Bekkar, H. K. Djemaa, and T. A. J. J. I. E. A. Alitouche, "Evaluation measures for models assessment over imbalanced data sets," in Journal of Information Engineering and Applications, 2013.
34- W. J. J. C. Youden, "Index for rating diagnostic tests," in Cancer, pp. 32-35, 1950.
35- S. Brin, R. Motwani, J. D. Ullman, and S. J. A. S. R. Tsur, "Dynamic itemset counting and implication rules for market basket data," in Proceedings of the 1997 ACM SIGMOD international conference on Management of datavol, pp. 255-264, 1997.
36- S. J. T. J. o. O. S. S. Raschka, "MLxtend: Providing machine learning and data science utilities and extensions to Python’s scientific computing stack," in Journal of Open Source Software, 2018.
37- J. BRAy and J. CuRTIS, "An ordination of upland forest communities of southern Wisconsin.-ecological Monographs," in journal of Ecological Monographs, 1957.
38- J. L. Fleiss, J. Cohen, and B. S. J. P. B. Everitt, "Large sample standard errors of kappa and weighted kappa," in Psychological Bulletin, p. 323, 1969.
39- M. Felkin, "Comparing classification results between n-ary and binary problems," in Quality Measures in Data Mining: Springer, pp. 277-301, 2007.
40- R. Ranawana and V. Palade, "Optimized Precision-A new measure for classifier performance evaluation," in 2006 IEEE International Conference on Evolutionary Computation, pp. 2254-2261, 2006.
41- V. García, R. A. Mollineda, and J. S. Sánchez, "Index of balanced accuracy: A performance measure for skewed class distributions," in Iberian Conference on Pattern Recognition and Image Analysis, pp. 441-448, 2009.
42- P. Branco, L. Torgo, and R. P. J. A. C. S. Ribeiro, "A survey of predictive modeling on imbalanced domains," in Journal ACM Computing Surveys (CSUR), p. 31, 2016.
43- K. Pearson, "Notes on Regression and Inheritance in the Case of Two Parents," in Proceedings of the Royal Society of London, p. 240-242, 1895.
44- W. J. I. Conover, New York, "Practical Nonparametric Statistics," in John Wiley and Sons, 1999.
45- Yule, G. U, "On the methods of measuring association between two attributes." in Journal of the Royal Statistical Society, pp. 579-652, 1912.
46- Batuwita, R. and Palade, V, "A new performance measure for class imbalance learning. application to bioinformatics problems," in Machine Learning and Applications, pp.545–550, 2009.
47- D. K. Lee, "Alternatives to P value: confidence interval and effect size," Korean journal of anesthesiology, vol. 69, no. 6, p. 555, 2016.
48- M. A. Raslich, R. J. Markert, and S. A. Stutes, "Selecting and interpreting diagnostic tests," Biochemia medica: Biochemia medica, vol. 17, no. 2, pp. 151-161, 2007.
49- D. E. Hinkle, W. Wiersma, and S. G. Jurs, "Applied statistics for the behavioral sciences," 1988.
50- A. Maratea, A. Petrosino, and M. Manzo, "Adjusted F-measure and kernel scaling for imbalanced data learning," Information Sciences, vol. 257, pp. 331-341, 2014.
51- L. Mosley, "A balanced approach to the multi-class imbalance problem," 2013.
52- M. Vijaymeena and K. Kavitha, "A survey on similarity measures in text mining," Machine Learning and Applications: An International Journal, vol. 3, no. 2, pp. 19-28, 2016.
53- Y. Otsuka, "The faunal character of the Japanese Pleistocene marine Mollusca, as evidence of climate having become colder during the Pleistocene in Japan," Biogeograph. Soc. Japan, vol. 6, pp. 165-170, 1936.
54- A. Tversky, "Features of similarity," Psychological review, vol. 84, no. 4, p. 327, 1977.
55- K. Boyd, K. H. Eng, and C. D. Page, "Area under the precision-recall curve: point estimates and confidence intervals," in Joint European conference on machine learning and knowledge discovery in databases, 2013, pp. 451-466: Springer.
56- J. Davis and M. Goadrich, "The relationship between Precision-Recall and ROC curves," in Proceedings of the 23rd international conference on Machine learning, 2006, pp. 233-240: ACM.
57- M. Kuhn, "Building predictive models in R using the caret package," Journal of statistical software, vol. 28, no. 5, pp. 1-26, 2008.
58- V. Labatut and H. Cherifi, "Accuracy measures for the comparison of classifiers," arXiv preprint, 2012.
59- S. Wallis, "Binomial confidence intervals and contingency tests: mathematical fundamentals and the evaluation of alternative methods," Journal of Quantitative Linguistics, vol. 20, no. 3, pp. 178-208, 2013.
60- D. Altman, D. Machin, T. Bryant, and M. Gardner, Statistics with confidence: confidence intervals and statistical guidelines. John Wiley & Sons, 2013.
61- J. A. Hanley and B. J. McNeil, "The meaning and use of the area under a receiver operating characteristic (ROC) curve," Radiology, vol. 143, no. 1, pp. 29-36, 1982.
62- E. B. Wilson, "Probable inference, the law of succession, and statistical inference," Journal of the American Statistical Association, vol. 22, no. 158, pp. 209-212, 1927.
63- A. Agresti and B. A. Coull, "Approximate is better than “exact” for interval estimation of binomial proportions," The American Statistician, vol. 52, no. 2, pp. 119-126, 1998.
64- C. S. Peirce, "The numerical measure of the success of predictions," Science, no. 93, pp. 453-454, 1884.
65- E. W. Steyerberg, B. Van Calster, and M. J. Pencina, "Performance measures for prediction models and markers: evaluation of predictions and classifications," Revista Española de Cardiología, vol. 64, no. 9, pp. 788-794, 2011.
66- A. J. Vickers and E. B. Elkin, "Decision curve analysis: a novel method for evaluating prediction models," Medical Decision Making, vol. 26, no. 6, pp. 565-574, 2006.
67- D. Knoke, G. W. Bohrnstedt, and A. P. Mee, Statistics for social data analysis. FE Peacock Publishers Itasca, IL, 2002
68- W. M. Rand, "Objective criteria for the evaluation of clustering methods," Journal of the American Statistical association, vol. 66, no. 336, pp. 846-850, 1971.
69- J. M. Santos and M. Embrechts, "On the use of the adjusted rand index as a metric for evaluating supervised classification," in International conference on artificial neural networks, 2009: Springer, pp. 175-184.
70- J. Cohen, "Weighted kappa: nominal scale agreement provision for scaled disagreement or partial credit," Psychological bulletin, vol. 70, no. 4, p. 213, 1968.
71- R. Bakeman and J. M. Gottman, Observing interaction: An introduction to sequential analysis. Cambridge university press, 1997.
72- S. Bangdiwala, "A graphical test for observer agreement," in 45th International Statistical Institute Meeting, 1985, vol. 1985, pp. 307-308.
73- K. Bangdiwala and H. Bryan, "Using SAS software graphical procedures for the observer agreement chart," in Proceedings of the SAS Users Group International Conference, 1987, vol. 12, pp. 1083-1088.
74- A. F. Hayes and K. Krippendorff, "Answering the call for a standard reliability measure for coding data," Communication methods and measures, vol. 1, no. 1, pp. 77-89, 2007.
75- M. Aickin, "Maximum likelihood estimation of agreement in the constant predictive probability model, and its relation to Cohen's kappa," Biometrics, pp. 293-302, 1990.

Cite

If you use PyCM in your research, we would appreciate citations to the following paper :

Haghighi, S., Jasemi, M., Hessabi, S. and Zolanvari, A. (2018). PyCM: Multiclass confusion matrix library in Python. Journal of Open Source Software, 3(25), p.729.
@article{Haghighi2018,
  doi = {10.21105/joss.00729},
  url = {https://doi.org/10.21105/joss.00729},
  year  = {2018},
  month = {may},
  publisher = {The Open Journal},
  volume = {3},
  number = {25},
  pages = {729},
  author = {Sepand Haghighi and Masoomeh Jasemi and Shaahin Hessabi and Alireza Zolanvari},
  title = {{PyCM}: Multiclass confusion matrix library in Python},
  journal = {Journal of Open Source Software}
}


Download PyCM.bib

JOSS
Zenodo DOI
Researchgate

Support

License

FOSSA Status

Donate to our project

If you do like our project and we hope that you do, can you please support us? Our project is not and is never going to be working for profit. We need the money just so we can continue doing what we do ;-) .

PyCM Donation

Comments
  • CM Aggregation

    CM Aggregation

    Description

    Because the datasets are usually huge, more often than not we do the training and testing in batches. So we have to calculate the confusion matrix of each batch, and then we should be able to aggregate them integrally. So I think it's useful to have a method like update_cm(total_cm, new_cm) or something like that.

    new feature 
    opened by fstackgeek 12
  • Imbalance dataset detection enhancement

    Imbalance dataset detection enhancement

    Description

    PyCM imbalance detection is weak, example :

    >>> cm = ConfusionMatrix(matrix={0:{0:60,1:0,2:0,3:0},1:{0:0,1:20,2:0,3:0},2:{0:0,1:0,2:20,3:0},3:{0:0,1:0,2:0,3:20}})
    >>> cm.print_matrix()
    Predict  0        1        2        3        
    Actual
    0        60       0        0        0        
    
    1        0        20       0        0        
    
    2        0        0        20       0        
    
    3        0        0        0        20       
    
    
    >>> cm.imbalance
    False
    
    enhancement question discussion 
    opened by sepandhaghighi 12
  • Class labels

    Class labels

    Reference Issues/PRs

    #358

    What does this implement/fix? Explain your changes.

    • classes optional parameter added to ConfusionMatrix, now you can use:
    >>> y_act=[0,0,0,0,0,1,1,1,1,1,1,2,2,2,2]
    >>> y_pre=[0,0,0,1,1,1,1,1,0,0,0,1,2,0,1]
    >>> cm = ConfusionMatrix(y_act,y_pre,classes=[1,2,0])
    >>> cm
    pycm.ConfusionMatrix(classes: [1, 2, 0])
    >>> cm.classes
    [1, 2, 0]
    >>> cm.to_array()
    array([[3, 0, 3],
           [2, 1, 1],
           [2, 0, 3]])
    >>> print(cm)
    Predict 1       2       0       
    Actual
    1       3       0       3       
    
    2       2       1       1       
    
    0       2       0       3       
    ...
    >>> cm = ConfusionMatrix(y_act,y_pre,classes=[1,2])
    >>> cm
    pycm.ConfusionMatrix(classes: [1, 2])
    >>> cm.classes
    [1, 2]
    >>> cm.to_array()
    array([[3, 0],
           [2, 1]])
    >>> print(cm)
    Predict 1       2       
    Actual
    1       3       0       
    
    2       2       1       
    ...
    >>> cm = ConfusionMatrix(y_act,y_pre,classes=[0,1,2,3])
    /home/user/Programing/Git/pycm/pycm/pycm_util.py:340: RuntimeWarning: Used classes is not a subset of classes in actual and predict vectors.
      warn(CLASSES_WARNING, RuntimeWarning)
    >>> cm
    pycm.ConfusionMatrix(classes: [0, 1, 2, 3])
    >>> cm.classes
    [0, 1, 2, 3]
    >>> cm.to_array()
    array([[3, 2, 0, 0],
           [3, 3, 0, 0],
           [1, 2, 1, 0],
           [0, 0, 0, 0]])
    >>> print(cm)
    Predict 0       1       2       3       
    Actual
    0       3       2       0       0       
    
    1       3       3       0       0       
    
    2       1       2       1       0       
    
    3       0       0       0       0       
    ...
    
    opened by sadrasabouri 11
  • Micro F1 equals accuracy

    Micro F1 equals accuracy

    This is not really a bug per se, but micro-averaged F1 is mathematically identical to overall accuracy (assuming you use the definition of Özgür, Özgür and Güngör, 2005), and hence should not be reported separately.

    bug enhancement 
    opened by wiedenhoeft 8
  • Plot method

    Plot method

    Reference Issues/PRs

    #330

    What does this implement/fix? Explain your changes.

    In this PR:

    • plot method added to ConfusionMatrix's methods.
    • add_number_label function added to pycm_utils.py.

    plot method is compatible with matplotlib and seaborn. this method may seems a little complex and it may be disturbed into several functions.

    @sepandhaghighi please help me with adding proper tests.

    And I think it will be great if we add a instance of plot method output in README.md too.

    opened by sadrasabouri 8
  • relabel bug

    relabel bug

    Description

    relabel method mapping order bug

    Steps/Code to Reproduce

    >>> 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.relabel({0:"L1",1:"L2",2:"L3"})
    >>> cm.relabel({'L3': 6, 'L1': 3, 'L2': 3})
    

    Expected Behavior

    Relabeling

    Actual Behavior

    Traceback (most recent call last):
      File "<pyshell#12>", line 1, in <module>
        cm.relabel({'L3': 6, 'L1': 3, 'L2': 3})
      File "C:\Users\Sepkjaer\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pycm-2.6-py3.5.egg\pycm\pycm_obj.py", line 633, in relabel
        raise pycmMatrixError(MAPPING_CLASS_NAME_ERROR)
    pycm.pycm_error.pycmMatrixError: Mapping class names error
    

    Operating System

    Windows 10

    Python Version

    Python 3.5

    PyCM Version (Use : pycm.__version__)

    2.6

    bug 
    opened by sepandhaghighi 7
  • normalized_table_calc inefficiency

    normalized_table_calc inefficiency

    Description

    Recently I found that normalized_table_calc function is too slow (more than 30% of the total execution time!!!) and it seems that the reason is the poor performance of numpy.around and built-in round function in scalar mode!!

    I think, we should define our custom rounder function, something like this :

    def custom_rounder(input_number,digit):
        p = float(10**digit)
        return int(input_number * p + 0.5)/p
    

    Take a look at this discussion

    performance 
    opened by sepandhaghighi 6
  • QI

    QI

    Reference Issues/PRs

    #267

    What does this implement/fix? Explain your changes.

    • Yule's Q interpretation
    • Minor edits in interpret functions

    Any other comments?

    enhancement new feature 
    opened by sepandhaghighi 6
  • Net benefit

    Net benefit

    Reference Issues/PRs

    #264 #266

    What does this implement/fix? Explain your changes.

    • Handler functions moved to pycm_handler.py
    • Error objects moved to pycm_error.py
    • Verified tests references updated
    • Verified tests moved to verified_test.py
    • Test system modified
    • CONTRIBUTING.md updated
    • Namespace optimized
    • Conda Managing Package broken link fixed
    • .gitattributes updated

    Any other comments?

    enhancement new feature 
    opened by sepandhaghighi 6
  • Bump numpy from 1.23.2 to 1.23.3

    Bump numpy from 1.23.2 to 1.23.3

    Bumps numpy from 1.23.2 to 1.23.3.

    Release notes

    Sourced from numpy's releases.

    v1.23.3

    NumPy 1.23.3 Release Notes

    NumPy 1.23.3 is a maintenance release that fixes bugs discovered after the 1.23.2 release. There is no major theme for this release, the main improvements are for some downstream builds and some annotation corner cases. The Python versions supported for this release are 3.8-3.11.

    Note that we will move to MacOS 11 for the NumPy 1.23.4 release, the 10.15 version currently used will no longer be supported by our build infrastructure at that point.

    Contributors

    A total of 16 people contributed to this release. People with a "+" by their names contributed a patch for the first time.

    • Aaron Meurer
    • Bas van Beek
    • Charles Harris
    • Ganesh Kathiresan
    • Gavin Zhang +
    • Iantra Solari+
    • Jyn Spring 琴春 +
    • Matti Picus
    • Rafael Cardoso Fernandes Sousa
    • Rafael Sousa +
    • Ralf Gommers
    • Rin Cat (鈴猫) +
    • Saransh Chopra +
    • Sayed Adel
    • Sebastian Berg
    • Serge Guelton

    Pull requests merged

    A total of 14 pull requests were merged for this release.

    • #22136: BLD: Add Python 3.11 wheels to aarch64 build
    • #22148: MAINT: Update setup.py for Python 3.11.
    • #22155: CI: Test NumPy build against old versions of GCC(6, 7, 8)
    • #22156: MAINT: support IBM i system
    • #22195: BUG: Fix circleci build
    • #22214: BUG: Expose heapsort algorithms in a shared header
    • #22215: BUG: Support using libunwind for backtrack
    • #22216: MAINT: fix an incorrect pointer type usage in f2py
    • #22220: BUG: change overloads to play nice with pyright.
    • #22221: TST,BUG: Use fork context to fix MacOS savez test
    • #22222: TYP,BUG: Reduce argument validation in C-based __class_getitem__

    ... (truncated)

    Commits
    • e47cbb6 Merge pull request #22234 from charris/prepare-1.23.3-release
    • e0e8991 REL: Prepare for the NumPy 1.23.3 release.
    • 9bf22bb BUG: Better report integer division overflow (backport) (#22230)
    • 0f0d355 Merge pull request #22224 from charris/backport-21928
    • 55a5ca7 Merge pull request #22223 from charris/backport-21981
    • 6cc4183 BUG: Fix the implementation of numpy.array_api.vecdot (#21928)
    • fb9666f BUG: Replace assert with correct error
    • fc0d627 TST: ensure np.equal.reduce raises a TypeError
    • 754ec89 Merge pull request #22222 from charris/backport-22212
    • 63ab75d Merge pull request #22221 from charris/backport-22204
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 5
  • Refs unification

    Refs unification

    Reference Issues/PRs

    #173

    What does this implement/fix? Explain your changes.

    The references are unified with IEEE format

    Any other comments?

    Please carefully compare the new references' titles with the previous ones. Be sure that the formats are correct.

    opened by alirezazolanvari 5
  • New Minor Features

    New Minor Features

    What does this implement/fix? Explain your changes.

    Two new magic method added:

    • __contains__ method
    >>> cm = ConfusionMatrix([1,1,1,1,0],[1,1,1,1,1])
    >>> 1 in cm
    True
    
    • __getitem__ method
    >>> cm = ConfusionMatrix([1,1,1,1,0],[1,1,1,1,1])
    >>> cm[0]
    array([0, 1])
    >>> cm[1][1]
    4
    
    enhancement 
    opened by sadrasabouri 1
  • Packaging on conda-forge

    Packaging on conda-forge

    Hi! It would be great to see this package on conda-forge, for people who may have only certain channels approved for use, though there's already a 'pycm' using the namespace there.

    I'd be happy to put in the feed-stock and list myself (and anyone else who would want) as a recipe maintainer - I'd started a WIP PR here (https://github.com/conda-forge/staged-recipes/pull/20795) though it will clearly need a rename to not clash with the ligo package pycm there. Sadly they're on first-come-first-serve. Any name request/suggestions would be great. Thanks!

    opened by dillonroach 4
  • Decimal points in plot method

    Decimal points in plot method

    Description

    百分比的混淆矩阵计算出来的位数太长,保存下来的图片数据是重合的,请问是否有办法设置一下小数点位数?真的十分感谢解答!!! image

    Steps/Code to Reproduce

    这是我的代码: cm = ConfusionMatrix(actual_vector=y_trueLabel, predict_vector=y_predictLabel, digit=4) cm.plot(cmap=plt.cm.Reds, normalized=True, number_label=True, plot_lib="matplotlib")
    plt.xticks(rotation=45) plt.savefig(fname="C:\Users\Graduate01\Desktop\222\%s" % '235')

    Expected Behavior

    Actual Behavior

    Operating System

    Python Version

    PyCM Version (Use : pycm.__version__)

    bug 
    opened by tanjiu 9
  • NPV Micro/Macro missed

    NPV Micro/Macro missed

    Description

    I received an email from Dr. Aonghus Lawlor (@aonghus) and it seems we forgot to add NPV Micro/Macro to stat. Currently, we support all other similar metrics (FPR, FNR, TPR, TNR, PPV) both micro and macro average.

    enhancement new feature 
    opened by sepandhaghighi 1
  • Number of decimal points

    Number of decimal points

    Description

    Control the number of decimal points in normalized mode.

    • print_normalized_matrix and plot methods

    Steps/Code to Reproduce

    >>> from pycm import *
    >>> cm = ConfusionMatrix(matrix={"Class1": {"Class1": 1, "Class2":2}, "Class2": {"Class1": 0, "Class2": 5}}, digit=2)
    >>> cm.print_normalized_matrix()
    

    Expected Behavior

    Predict       Class1        Class2        
    Actual
    Class1        0.33          0.66      
    
    Class2        0.0           1.0   
    

    Actual Behavior

    Predict       Class1        Class2        
    Actual
    Class1        0.33333       0.66667       
    
    Class2        0.0           1.0   
    

    Operating System

    Windows 10

    Python Version

    Python 3.8.0

    PyCM Version (Use : pycm.__version__)

    3.4

    bug 
    opened by sepandhaghighi 0
  • Adding string classes directly in ConfusionMatrix removes all stats.

    Adding string classes directly in ConfusionMatrix removes all stats.

    Description

    I was going to add my own custom labels in ConfusionMatrix. However, this blanked out all other values.

    Steps/Code to Reproduce

    Input:

    cm1 = ConfusionMatrix(
        y_true, y_pred, digit=5, classes=["normal", "lgg", "hgg"]
    )
    

    Output:

    /Users/lewiuberg/Library/Caches/pypoetry/virtualenvs/tumorclass.info-OrbyvotM-py3.9/lib/python3.9/site-packages/pycm/pycm_util.py:387: RuntimeWarning: Used classes is not a subset of classes in actual and predict vectors.
      warn(CLASSES_WARNING, RuntimeWarning)
    

    Input:

    cm1
    

    Output:

    pycm.ConfusionMatrix(classes: ['normal', 'lgg', 'hgg'])
    

    Input:

    print(cm1)
    

    Output:

    Predict      normal       lgg          hgg          
    Actual
    normal       0            0            0            
    
    lgg          0            0            0            
    
    hgg          0            0            0            
    
    
    
    
    
    Overall Statistics : 
    
    95% CI                                                            (None,None)
    ACC Macro                                                         None
    ARI                                                               None
    AUNP                                                              None
    AUNU                                                              None
    Bangdiwala B                                                      None
    ...
    

    Operating System

    macOS Monterey V 12.0.1

    Python Version

    3.9

    PyCM Version (Use : pycm.__version__)

    3.3

    opened by lewiuberg 4
Releases(v3.7)
  • v3.7(Dec 15, 2022)

  • v3.6(Aug 17, 2022)

    • Hamming distance added #350
    • Braun-Blanquet similarity added #349
    • classes parameter added to matrix_params_from_table function
    • Matrices with numpy.integer elements are now accepted
    • Arrays added to matrix parameter accepting formats #402
    • Website changed to http://www.pycm.io
    • Document modified
    • README.md modified

    Acknowledgment

    This version has been funded by the NLnet foundation

    Source code(tar.gz)
    Source code(zip)
  • v3.5(Apr 27, 2022)

    • Anaconda workflow added
    • Custom iterating setting added #409
    • Custom casting setting added #409
    • plot method updated #408
    • class_statistics function modified
    • overall_statistics function modified
    • BCD_calc function modified
    • CONTRIBUTING.md updated
    • CODE_OF_CONDUCT.md updated #399
    • Document modified
    Source code(tar.gz)
    Source code(zip)
  • v3.4(Jan 26, 2022)

    • Colab badge added #389
    • Discord badge added #397
    • brier_score method added #219
    • J (Jaccard index) section in Document.ipynb updated #401
    • save_obj method updated #219
    • Python 3.10 added to test.yml #391
    • Example-3 updated #405
    • Docstrings of the functions updated #345
    • CONTRIBUTING.md updated #345
    Source code(tar.gz)
    Source code(zip)
  • v3.3(Oct 27, 2021)

    • __compare_weight_handler__ function added #347
    • is_imbalanced parameter added to ConfusionMatrix __init__ method #276
    • class_benchmark_weight and overall_benchmark_weight parameters added to Compare __init__ method #347
    • statistic_recommend function modified #276
    • Compare weight parameter renamed to class_weight #347
    • Document modified
    • License updated
    • AUTHORS.md updated
    • README.md modified
    • Block diagrams updated
    Source code(tar.gz)
    Source code(zip)
  • v3.2(Aug 11, 2021)

    • classes_filter function added #358
    • classes parameter added to matrix_params_calc function #358
    • classes parameter added to __obj_vector_handler__ function #358
    • classes parameter added to ConfusionMatrix __init__ method #358
    • name parameter removed from html_init function
    • shortener parameter added to html_table function #364
    • shortener parameter added to save_html method #364
    • Document modified
    • HTML report modified
    Source code(tar.gz)
    Source code(zip)
  • v3.1(Mar 11, 2021)

    • requirements-splitter.py added
    • sensitivity_index method added #357
    • Test system modified #361
    • overall_statistics function modified #346
    • HTML report modified #367
    • Document modified
    • References format updated #173
    • CONTRIBUTING.md updated
    Source code(tar.gz)
    Source code(zip)
  • v3.0(Oct 26, 2020)

    • plot_test.py added #330
    • axes_gen function added #330
    • add_number_label function added #330
    • plot method added #330
    • combine method added #326
    • matrix_combine function added #326
    • Document modified
    • README.md modified
    • Example-2 deprecated #330
    • Example-7 deprecated #330
    • Error messages modified
    Source code(tar.gz)
    Source code(zip)
  • v2.9(Sep 23, 2020)

  • v2.8(Jul 9, 2020)

    • label_map attribute added #256 #323
    • positions attribute added #256
    • position method added #256
    • Krippendorff's Alpha added #313
    • Aickin's Alpha added #317
    • weighted_alpha method added #313
    • Single class bug fixed #310
    • CLASS_NUMBER_ERROR error type changed to pycmMatrixError
    • relabel method bug fixed #323
    • Document modified
    • README.md modified
    Source code(tar.gz)
    Source code(zip)
  • v2.7(May 11, 2020)

    • average method added #299
    • weighted_average method added #274
    • weighted_kappa method added #243
    • pycmAverageError class added #274 #299
    • Bangdiwala's B added #303
    • MATLAB examples added #268
    • Github action added #297
    • Document modified
    • README.md modified
    • relabel method bug fixed #293
    • sparse_table_print function bug fixed #293
    • matrix_check function bug fixed
    • Minor bug in Compare class fixed #294
    • Class names mismatch bug fixed #293
    Source code(tar.gz)
    Source code(zip)
  • v2.6(Mar 25, 2020)

    • custom_rounder function added #279
    • complement function added
    • sparse_matrix attribute added #185
    • sparse_normalized_matrix attribute added #185
    • Net benefit (NB) added #264
    • Yule's Q interpretation (QI) added #267
    • Adjusted Rand index (ARI) added #270
    • TNR micro/macro added #284
    • FPR micro/macro added #284
    • FNR micro/macro added #284
    • sparse parameter added to print_matrix,print_normalized_matrix and save_stat methods #185
    • header parameter added to save_csv method #282
    • Handler functions moved to pycm_handler.py
    • Error objects moved to pycm_error.py
    • Verified tests references updated
    • Verified tests moved to verified_test.py
    • Test system modified
    • CONTRIBUTING.md updated
    • Namespace optimized
    • README.md modified #266
    • Document modified
    • print_normalized_matrix method modified #279
    • normalized_table_calc function modified #279
    • setup.py modified
    • summary mode updated #284
    • Dockerfile updated
    • Python 3.8 added to .travis.yaml and appveyor.yml
    Source code(tar.gz)
    Source code(zip)
  • v2.5(Oct 16, 2019)

    • __version__ variable added #241
    • Individual classification success index (ICSI) added #238
    • Classification success index (CSI) added #238
    • Example-8 (Confidence interval) added #237
    • install.sh added
    • autopep8.sh added
    • Dockerfile added
    • CI method added (supported statistics : ACC,AUC,Overall ACC,Kappa,TPR,TNR,PPV,NPV,PLR,NLR,PRE) #237
    • test.sh moved to .travis folder
    • Python 3.4 support dropped
    • Python 2.7 support dropped
    • AUTHORS.md updated
    • save_stat,save_csv and save_html methods Non-ASCII character bug fixed #246
    • Mixed type input vectors bug fixed #240
    • CONTRIBUTING.md updated #245
    • Example-3 updated #239
    • README.md modified #248
    • Document modified #248
    • CI attribute renamed to CI95 #237
    • kappa_se_calc function renamed to kappa_SE_calc #237
    • se_calc function modified and renamed to SE_calc #237
    • CI/SE functions moved to pycm_ci.py #237
    • Minor bug in save_html method fixed
    Source code(tar.gz)
    Source code(zip)
  • v2.4(Jul 31, 2019)

    • Tversky index (TI) added #214
    • Area under the PR curve (AUPR) added #216
    • FUNDING.yml added
    • AUC_calc function modified
    • Document modified #225
    • summary parameter added to save_html,save_stat,save_csv and stat methods #217
    • sample_weight bug in numpy array format fixed #227
    • Inputs manipulation bug fixed #226
    • Test system modified #229 @sadrasabouri
    • Warning system modified #228
    • alt_link parameter added to save_html method and online_help function #232
    • Compare class tests moved to compare_test.py
    • Warning tests moved to warning_test.py
    Source code(tar.gz)
    Source code(zip)
  • v2.3(Jun 26, 2019)

    • Adjusted F-score (AGF) added #209
    • Overlap coefficient (OC) added #212
    • Otsuka-Ochiai coefficient (OOC) added #213
    • save_stat and save_vector parameters added to save_obj method #210
    • Document modified #221
    • README.md modified
    • Parameters recommendation for imbalance dataset modified
    • Minor bug in Compare class fixed
    • pycm_help function modified
    • Benchmarks color modified #221
    Source code(tar.gz)
    Source code(zip)
  • v2.2(May 29, 2019)

    • Negative likelihood ratio interpretation (NLRI) added
    • Cramer's benchmark (SOA5) added
    • Matthews correlation coefficient interpretation (MCCI) added #204
    • Matthews's benchmark (SOA6) added #204
    • F1 macro added
    • F1 micro added
    • Accuracy macro added #205
    • Compare class score calculation modified
    • Parameters recommendation for multi-class dataset modified
    • Parameters recommendation for imbalance dataset modified
    • README.md modified
    • Document modified
    • Logo updated
    Source code(tar.gz)
    Source code(zip)
  • v2.1(May 6, 2019)

    • Adjusted geometric mean (AGM) added #177
    • Yule's Q (Q) added #193
    • Compare class and parameters recommendation system block diagrams added #192
    • Document links bug fixed #194
    • Document modified #173
    Source code(tar.gz)
    Source code(zip)
  • v2.0(Apr 15, 2019)

    • G-Mean (GM) added #178
    • Index of balanced accuracy (IBA) added #176
    • Optimized precision (OP) added #152
    • Pearson's C (C) added #180
    • Compare class added #111
    • Parameters recommendation warning added #174
    • ConfusionMatrix equal method added #181
    • Document modified #173
    • stat_print function bug fixed
    • table_print function bug fixed
    • Beta parameter renamed to beta (F_calc function & F_beta method)
    • Parameters recommendation for imbalance dataset modified
    • normalize parameter added to save_html method #183
    • pycm_func.py splitted into pycm_class_func.py and pycm_overall_func.py
    • vector_filter,vector_check,class_check and matrix_check functions moved to pycm_util.py
    • RACC_calc and RACCU_calc functions exception handler modified #187
    • Docstrings modified
    Source code(tar.gz)
    Source code(zip)
  • v1.9(Feb 25, 2019)

    • Automatic/Manual (AM) added #144
    • Bray-Curtis dissimilarity (BCD) added #143
    • CODE_OF_CONDUCT.md added #151
    • ISSUE_TEMPLATE.md added #156
    • PULL_REQUEST_TEMPLATE.md added #156
    • CONTRIBUTING.md added #155
    • X11 color names support for save_html method added #146
    • Parameters recommendation system added #112
    • Warning message for high dimension matrix print added #120
    • Interactive notebooks section (binder) added #142
    • save_matrix and normalize arguments added to save_csv method #120
    • README.md modified
    • Document modified #149 #164
    • ConfusionMatrix.__init__ optimized #145
    • Document and examples output files moved to different folders #149
    • Test system modified #138
    • relabel method bug fixed #167
    Source code(tar.gz)
    Source code(zip)
  • v1.8(Jan 5, 2019)

    • Lift Score (LS) added #128
    • color argument added to save_html method #130
    • version_check.py added
    • Error messages modified #132
    • Document modified #131
    • Website changed to http://www.pycm.ir
    • Interpretation functions moved to pycm_interpret.py
    • Utility functions moved to pycm_util.py
    • Unnecessary else and elif removed
    • == changed to is
    Source code(tar.gz)
    Source code(zip)
  • v1.7(Dec 18, 2018)

    • Gini Index (GI) added #119
    • Example-7 added #121
    • pycm_profile.py added
    • class_name argument added to stat,save_stat,save_csv and save_html methods #118
    • overall_param and class_param arguments empty list bug fixed #118
    • matrix_params_calc, matrix_params_from_table and vector_filter functions optimized #118
    • overall_MCC_calc, CEN_misclassification_calc and convex_combination functions optimized #118
    • Document modified #124
    Source code(tar.gz)
    Source code(zip)
  • v1.6(Dec 5, 2018)

    • AUC Value Interpretation (AUCI) added #114
    • Example-6 added #113
    • Anaconda cloud package added #90
    • overall_param and class_param arguments added to stat,save_stat and save_html methods
    • class_param argument added to save_csv method
    • _ removed from overall statistics names
    • README.md modified
    • Document modified
    Source code(tar.gz)
    Source code(zip)
  • v1.5(Nov 26, 2018)

    • Relative Classifier Information (RCI) added #82
    • Discriminator Power (DP) added #104
    • Youden's Index (Y) added #105
    • Discriminant Power Interpretation (DPI) added #107
    • Positive Likelihood Ratio Interpretation (PLRI) added #106
    • __len__ method added
    • relabel method added #98
    • __class_stat_init__ function added
    • __overall_stat_init__ function added
    • matrix attribute added #99
    • normalized_matrix attribute added #99
    • normalized_table attribute added #99
    • Python 3.7 added to .travis.yaml & appveyor.yml
    • README.md modified
    • Document modified
    • LR+ renamed to PLR
    • LR- renamed to NLR
    • normalized_matrix method renamed to print_normalized_matrix #99
    • matrix method renamed to print_matrix #99
    • entropy_calc fixed
    • cross_entropy_calc fixed
    • conditional_entropy_calc fixed
    • print_table bug for large numbers fixed
    • JSON key bug in save_obj fixed #108
    • transpose bug in save_obj fixed #108
    Source code(tar.gz)
    Source code(zip)
  • v1.4(Nov 11, 2018)

    • Area Under Curve added #83
    • AUNU added #83
    • AUNP added #83
    • Class Balance Accuracy added #81
    • Global Performance Index (RR) added #80
    • Overall MCC added #75
    • Distance index (dInd) added #84
    • Similarity index (sInd) added #84
    • one_vs_all added #76
    • dev-requirements.txt added
    • README.md modified #85
    • Document modified #85
    • save_stat modified #78
    • requirements.txt modified
    Source code(tar.gz)
    Source code(zip)
  • v1.3(Oct 9, 2018)

    • Confusion Entropy added #72
    • Overall Confusion Entropy added #72
    • Modified Confusion Entropy added #73
    • Overall Modified Confusion Entropy added #73
    • Information Score added #71
    • README.md modified
    Source code(tar.gz)
    Source code(zip)
  • v1.2(Oct 1, 2018)

    • NIR (No Information Rate) added
    • P-Value added
    • sample_weight added
    • transpose added
    • README.md modified
    • Key error in some parameters fixed
    • OSX env added to .travis.yml
    Source code(tar.gz)
    Source code(zip)
  • v1.1(Sep 8, 2018)

    • Zero-one loss added
    • Support added
    • online_help function added
    • README.md modified
    • html_table function modified
    • table_print function modified
    • normalized_table_print function modified
    Source code(tar.gz)
    Source code(zip)
  • v1.0(Aug 30, 2018)

  • v0.9.5(Jul 8, 2018)

  • v0.9(Jun 27, 2018)

Owner
Sepand Haghighi
Open Source Enthusiast
Sepand Haghighi
AB-test-analyzer - Python class to perform AB test analysis

AB-test-analyzer Python class to perform AB test analysis Overview This repo con

null 13 Jul 16, 2022
These data visualizations were created as homework for my CS40 class. I hope you enjoy!

Data Visualizations These data visualizations were created as homework for my CS40 class. I hope you enjoy! Nobel Laureates by their Country of Birth

null 9 Sep 2, 2022
Graphical display tools, to help students debug their class implementations in the Carcassonne family of projects

carcassonne_tools Graphical display tools, to help students debug their class implementations in the Carcassonne family of projects NOTE NOTE NOTE The

null 1 Nov 8, 2021
Here I plotted data for the average test scores across schools and class sizes across school districts.

HW_02 Here I plotted data for the average test scores across schools and class sizes across school districts. Average Test Score by Race This graph re

null 7 Oct 27, 2021
A Simple Flask-Plotly Example for NTU 110-1 DSSI Class

A Simple Flask-Plotly Example for NTU 110-1 DSSI Class Live Demo Prerequisites We will use Flask and Ploty to build a Flask application. If you haven'

Ting Ni Wu 1 Dec 11, 2021
Declarative statistical visualization library for Python

Altair http://altair-viz.github.io Altair is a declarative statistical visualization library for Python. With Altair, you can spend more time understa

Altair 8k Jan 5, 2023
Cartopy - a cartographic python library with matplotlib support

Cartopy is a Python package designed to make drawing maps for data analysis and visualisation easy. Table of contents Overview Get in touch License an

null 1.2k Jan 1, 2023
a plottling library for python, based on D3

Hello August 2013 Hello! Maybe you're looking for a nice Python interface to build interactive, javascript based plots that look as nice as all those

Mike Dewar 1.4k Dec 28, 2022
A Python Library for Self Organizing Map (SOM)

SOMPY A Python Library for Self Organizing Map (SOM) As much as possible, the structure of SOM is similar to somtoolbox in Matlab. It has the followin

Vahid Moosavi 497 Dec 29, 2022
NorthPitch is a python soccer plotting library that sits on top of Matplotlib

NorthPitch is a python soccer plotting library that sits on top of Matplotlib.

Devin Pleuler 30 Feb 22, 2022
The interactive graphing library for Python (includes Plotly Express) :sparkles:

plotly.py Latest Release User forum PyPI Downloads License Data Science Workspaces Our recommended IDE for Plotly’s Python graphing library is Dash En

Plotly 12.7k Jan 5, 2023
🎨 Python Echarts Plotting Library

pyecharts Python ❤️ ECharts = pyecharts English README ?? 简介 Apache ECharts (incubating) 是一个由百度开源的数据可视化,凭借着良好的交互性,精巧的图表设计,得到了众多开发者的认可。而 Python 是一门富有表达

pyecharts 13.1k Jan 3, 2023
Declarative statistical visualization library for Python

Altair http://altair-viz.github.io Altair is a declarative statistical visualization library for Python. With Altair, you can spend more time understa

Altair 6.4k Feb 13, 2021
Python library that makes it easy for data scientists to create charts.

Chartify Chartify is a Python library that makes it easy for data scientists to create charts. Why use Chartify? Consistent input data format: Spend l

Spotify 3.2k Jan 4, 2023
:small_red_triangle: Ternary plotting library for python with matplotlib

python-ternary This is a plotting library for use with matplotlib to make ternary plots plots in the two dimensional simplex projected onto a two dime

Marc 611 Dec 29, 2022
The interactive graphing library for Python (includes Plotly Express) :sparkles:

plotly.py Latest Release User forum PyPI Downloads License Data Science Workspaces Our recommended IDE for Plotly’s Python graphing library is Dash En

Plotly 8.9k Feb 18, 2021
🎨 Python Echarts Plotting Library

pyecharts Python ❤️ ECharts = pyecharts English README ?? 简介 Apache ECharts (incubating) 是一个由百度开源的数据可视化,凭借着良好的交互性,精巧的图表设计,得到了众多开发者的认可。而 Python 是一门富有表达

pyecharts 10.6k Feb 18, 2021
Declarative statistical visualization library for Python

Altair http://altair-viz.github.io Altair is a declarative statistical visualization library for Python. With Altair, you can spend more time understa

Altair 6.4k Feb 18, 2021
Python library that makes it easy for data scientists to create charts.

Chartify Chartify is a Python library that makes it easy for data scientists to create charts. Why use Chartify? Consistent input data format: Spend l

Spotify 2.8k Feb 18, 2021