Compute metrics for assessing the performance of binary classification models.
The Confusion Matrix:
Total Samples (ts) | Actual Positives (ap) | Actual Negatives (an) |
Predicted Positives (pp) | True Positives (tp) | False Positives (fp) |
Predicted Negatives (pn) | False Positives (fn) | True Negatives (tn) |
Compute the Error.
error = (fp + fn) / ts
Input
- y - classes (two classes) [1D numpy array integer]
- p - prediction (two classes) [1D numpy array integer]
Output
- error
Compute the Error for positive samples.
errp = fp / ap
Input
- y - classes (two classes +1 and -1) [1D numpy array integer]
- p - prediction (two classes +1 and -1) [1D numpy array integer]
Output
- error for positive samples
Compute the Error for negative samples.
errn = fn / an
Input
- y - classes (two classes +1 and -1) [1D numpy array integer]
- p - prediction (two classes +1 and -1) [1D numpy array integer]
Output
- error for negative samples
Compute the Accuracy.
accuracy = (tp + tn) / ts
Input
- y - classes (two classes) [1D numpy array integer]
- p - prediction (two classes) [1D numpy array integer]
Output
- accuracy
Compute the Sensitivity.
sensitivity = tp / ap
Input
- y - classes (two classes +1 and -1) [1D numpy array integer]
- p - prediction (two classes +1 and -1) [1D numpy array integer]
Output
- sensitivity
Compute the Specificity.
specificity = tn / an
Input
- y - classes (two classes +1 and -1) [1D numpy array integer]
- p - prediction (two classes +1 and -1) [1D numpy array integer]
Output
- specificity
Compute the single AUC.
Input
- y - classes (two classes +1 and -1) [1D numpy array integer]
- p - prediction (two classes +1 and -1) [1D numpy array integer]
Output
- singleAUC
Compute the AUC by using the Wilcoxon-Mann-Whitney formula.
Input
- y - classes (two classes +1 and -1) [1D numpy array integer]
- r - real-valued prediction [1D numpy array float]
Output
- wmwAUC
Compute the Positive Predictive Value (PPV).
PPV = tp / pp
Input
- y - classes (two classes +1 and -1) [1D numpy array integer]
- p - prediction (two classes +1 and -1) [1D numpy array integer]
Output
- PPV
Compute the Negative Predictive Value (NPV).
NPV = tn / pn
Input
- y - classes (two classes +1 and -1) [1D numpy array integer]
- p - prediction (two classes +1 and -1) [1D numpy array integer]
Output
- NPV
Compute the Matthews Correlation Coefficient (MCC).
MCC = ((tp*tn)-(fp*fn)) / sqrt((tp+fn)*(tp+fp)*(tn+fn)*(tn+fp))
Input
- y - classes (two classes +1 and -1) [1D numpy array integer]
- p - prediction (two classes +1 and -1) [1D numpy array integer]
Output
- MCC