Metric Functions¶
Compute metrics for assessing the performance of classification/regression 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 Negatives (fn) | True Negatives (tn) |
-
mlpy.
err
(y, p)¶ 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
-
mlpy.
errp
(y, p)¶ 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
-
mlpy.
errn
(y, p)¶ 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
-
mlpy.
acc
(y, p)¶ 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
-
mlpy.
sens
(y, p)¶ 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
-
mlpy.
spec
(y, p)¶ 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
-
mlpy.
single_auc
(y, p)¶ 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
-
mlpy.
wmw_auc
(y, r)¶ 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
-
mlpy.
ppv
(y, p)¶ 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
-
mlpy.
npv
(y, p)¶ 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
-
mlpy.
mcc
(y, p)¶ 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
-
mlpy.
mse
(y, p)¶ Mean Squared Error
-
mlpy.
r2
(y, p)¶ Coefficient of determination (R^2)
R^2 is computed as square of the correlation coefficient.