sepandhaghighi/pycm

Multi-class confusion matrix library in Python

What it solves

PyCM provides a comprehensive set of tools for evaluating the performance of classification models. It simplifies the process of creating confusion matrices and calculating a wide array of statistical metrics to determine how accurately a model is predicting different classes, especially in multi-class scenarios.

How it works

Users can generate a confusion matrix by providing either raw data vectors (actual vs. predicted labels) or a pre-existing matrix. The library then calculates detailed statistics for each class (such as Accuracy, F1-score, Precision, and Recall) and overall statistics (such as Kappa and Macro-averaged metrics). It also includes specialized tools for plotting matrices and generating performance curves—including ROC, Precision-Recall, Precision, Recall, and F1 curves—by binarizing multi-class output using a "One vs. Rest" strategy.

Who it’s for

It is primarily designed for data scientists and machine learning practitioners who need a robust, "swiss-army knife" tool for the post-classification evaluation of predictive models.

Highlights

  • Flexible Input: Supports both input data vectors and direct matrix input.
  • Extensive Metrics: Provides a broad array of class-specific and overall statistics parameters.
  • Visualization: Integrated plotting capabilities using Matplotlib or Seaborn.
  • Advanced Analysis: Includes tools for calculating optimal thresholds and generating various performance curves (ROC, PR, F1, etc.).
  • Interoperability: Supports NumPy arrays and can be integrated with MATLAB.