Metric Functions

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)

Error

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

Accuracy

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

Sensitivity and Specificity

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

AUC

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

Other

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

Table Of Contents

Previous topic

Resampling Methods

Next topic

Feature List Analysis

This Page