Skip to content

Instantly share code, notes, and snippets.

@joyadauche
Last active May 31, 2020 19:17
Show Gist options
  • Save joyadauche/992e1f1cc8ba4fc9825f49847289b6f3 to your computer and use it in GitHub Desktop.
Save joyadauche/992e1f1cc8ba4fc9825f49847289b6f3 to your computer and use it in GitHub Desktop.
The ML Maven: Introducing the Confusion Matrix

A confusion matrix example for earthquake happenings in Wakanda

Number of samples = 240

PREDICTED: NO: 0 PREDICTED: YES: 1 TOTAL
ACTUAL: NO: 0 60 20 80
ACTUAL: YES: 1 10 150 160
TOTAL 70 170
PREDICTED: NO: 0 PREDICTED: YES: 1
ACTUAL: NO: 0 TRUE NEGATIVES FALSE POSITIVES
ACTUAL: YES: 1 FALSE NEGATIVES TRUE POSITIVES

Recall

TP / TP + FN = 150 / 150 + 10 = 150 / 160 = 0.94

To express as a percentage, multiply by 100 = 0.94 * 100 = 94%

Note that TP + FN is the ACTUAL YES

Specificity

TN / TN + FP = 60 / 60 + 20 = 60 / 80 = 0.75

To express as a percentage, multiply by 100 = 0.75 * 100 = 75%

Note that TN + FP is the ACTUAL NO

Precision

TP / TP + FP = 150 / 150 + 20 = 150 / 170 = 0.88

To express as a percentage, multiply by 100 = 0.88 * 100 = 88%

Note that TP + FP is the PREDICTED YES

Negative Predictive Value

TN / TN + FN = 60 / 60 + 10 = 60 / 70 = 0.85

To express as a percentage, multiply by 100 = 0.85 * 100 = 85%

Note that TN + FN is the PREDICTED NO

F1 Score

2 * (Precision * Recall / Precision + Recall) = 2 * ((0.88 * 0.94) / (0.88 + 0.94)) = 2 * (0.83 / 1.82) = 2 * 0.46 = 0.92

To express as a percentage, multiply by 100 = 0.92 * 100 = 92%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment