Skip to main content
Albero Academy

Classification Metrics

Beyond accuracy — precision, recall and F1.

Classification10 min

Accuracy alone is misleading — especially with imbalanced classes. Precision, recall and F1 tell you what kind of errors your classifier makes.

The key metrics

MetricAnswers
AccuracyFraction correct — misleading if classes are imbalanced
PrecisionOf predicted positives, how many are right?
RecallOf actual positives, how many did we catch?
F1Harmonic mean of precision and recall
one report has it all
from sklearn.metrics import classification_report
print(classification_report(y_test, model.predict(X_test)))
# precision, recall, f1 per class + accuracy

Why accuracy misleads

Key takeaways

  1. 01Accuracy is misleading with imbalanced classes.
  2. 02Precision = correct among predicted positives; recall = caught among actual positives.
  3. 03F1 is the harmonic mean of precision and recall.
  4. 04classification_report gives all of them per class; choose the metric that fits the cost of each error.

Finished this chapter?

Mark it complete to track your progress through Scikit-learn.