Menu

Calculating Precision, Recall, and F1-Score

Calculating Precision, Recall, and F1-Score

Although the Classification Report displays these metrics, we can also calculate them individually for a better understanding.

Code

from sklearn.metrics import (

precision_score,

recall_score,

f1_score

)

precision = precision_score(y_test, y_pred)

recall = recall_score(y_test, y_pred)

f1 = f1_score(y_test, y_pred)

print("Precision:", precision)

print("Recall:", recall)

print("F1 Score:", f1)

Explanation

Each metric focuses on a different aspect of model performance.

  • Precision emphasizes reducing false positives.
  • Recall emphasizes reducing false negatives.
  • F1-Score balances both.