eval-metrics
Evaluation metrics for machine learning
Design
The goal of this library is to provide an intuitive collection of functions for computing evaluation metrics commonly
encountered in machine learning. Metrics are separated into modules for either classification or regression, with
the classification module supporting both binary and multi-class tasks. This distinction between binary and multi-class
classification is made explicit to underscore the fact that there are subtle differences in certain metrics between the
two cases (i.e. multi-class metrics often require averaging methods). Metrics can often fail to be defined for a
variety of numerical reasons, and in these cases Result types are used to make this fact apparent.
Supported Metrics
| Metric | Task | Description |
|---|---|---|
| Accuracy | Binary Classification | Binary Class Accuracy |
| Precision | Binary Classification | Binary Class Precision |
| Recall | Binary Classification | Binary Class Recall |
| F-1 | Binary Classification | Harmonic Mean of Precision and Recall |
| MCC | Binary Classification | Matthews Correlation Coefficient |
| ROC Curve | Binary Classification | Receiver Operating Characteristic Curve |
| AUC | Binary Classification | Area Under ROC Curve |
| PR Curve | Binary Classification | Precision-Recall Curve |
| AP | Binary Classification | Average Precision |
| Accuracy | Multi-Class Classification | Multi-Class Accuracy |
| Precision | Multi-Class Classification | Multi-Class Precision |
| Recall | Multi-Class Classification | Multi-Class Recall |
| F-1 | Multi-Class Classification | Multi-Class F1 |
| Rk | Multi-Class Classification | K-Category Correlation Coefficient as described by Gorodkin (2004) |
| M-AUC | Multi-Class Classification | Multi-Class AUC as described by Hand and Till (2001) |
| RMSE | Regression | Root Mean Squared Error |
| MSE | Regression | Mean Squared Error |
| MAE | Regression | Mean Absolute Error |
| R-Square | Regression | Coefficient of Determination |
| Correlation | Regression | Linear Correlation Coefficient |
Usage
Binary Classification
The BinaryConfusionMatrix struct provides functionality for computing common binary classification metrics.
use EvalError;
use BinaryConfusionMatrix;
o=========================o
| Label |
o=========================o
| Positive | Negative |
o==============o============o============|============o
| | Positive | 2 | 2 |
| Prediction |============|------------|------------|
| | Negative | 1 | 3 |
o==============o============o=========================o
In addition to the metrics derived from the confusion matrix, ROC curves and PR curves can be computed, providing metrics such as AUC and AP.
use EvalError;
use ;
Multi-Class Classification
The MultiConfusionMatrix struct provides functionality for computing common multi-class classification metrics.
Additionally, averaging methods must be explicitly provided for several of these metrics.
use EvalError;
use ;
o===================================o
| Label |
o===================================o
| Class-1 | Class-2 | Class-3 |
o==============o===========o===========|===========|===========o
| | Class-1 | 1 | 1 | 1 |
| |===========|-----------|-----------|-----------|
| Prediction | Class-2 | 1 | 1 | 0 |
| |===========|-----------|-----------|-----------|
| | Class-3 | 0 | 0 | 2 |
o==============o===========o===================================o
In addition to these global metrics, per-class metrics can be obtained as well.
use EvalError;
use ;
[Ok(0.5714285714285714), Ok(0.7142857142857143), Ok(0.8571428571428571)]
[Ok(0.3333333333333333), Ok(0.5), Ok(1.0)]
[Ok(0.5), Ok(0.5), Ok(0.6666666666666666)]
[Ok(0.4), Ok(0.5), Ok(0.8)]
[Ok(0.09128709291752773), Ok(0.3), Ok(0.7302967433402215)]
In addition to the metrics derived from the confusion matrix, the M-AUC (multi-class AUC) metric as described by Hand and Till (2001) is provided as a standalone function:
let mauc = m_auc?;
Regression
All regression metrics operate on a pair of scores and labels.
use EvalError;
use *;