How to Calculate Precision, Recall, and F1 Score in Supervised Classification Problems

In supervised classification problems, evaluating the performance of a model is essential. Metrics like precision, recall, and F1 score provide insights into how well the model predicts different classes. Understanding how to calculate these metrics helps in selecting and tuning models effectively.

Precision

Precision measures the proportion of positive predictions that are correct. It is calculated as the number of true positives divided by the sum of true positives and false positives.

The formula for precision is:

Precision = True Positives / (True Positives + False Positives)

Recall

Recall, also known as sensitivity, measures the proportion of actual positives that are correctly identified. It is calculated as the number of true positives divided by the sum of true positives and false negatives.

The formula for recall is:

Recall = True Positives / (True Positives + False Negatives)

F1 Score

The F1 score combines precision and recall into a single metric by calculating their harmonic mean. It provides a balanced measure, especially when class distribution is uneven.

The formula for F1 score is:

F1 Score = 2 * (Precision * Recall) / (Precision + Recall)

Summary

  • Precision indicates the accuracy of positive predictions.
  • Recall measures the ability to identify all positive instances.
  • The F1 score balances precision and recall into a single metric.