Sobes.tech
Intern

How do Precision and Recall behave under class imbalance? Example: 95 ones and 5 zeros, the model always predicts 1.

sobes.tech AI

Answer from AI

In a situation with a strong class imbalance (for example, 95 ones and 5 zeros), the metrics Precision and Recall can behave unexpectedly.

If the model always predicts class 1:

  • Recall for class 1 will be 1.0 (100%) because all actual ones are correctly predicted.
  • Precision for class 1 will also be 1.0, as all predictions are ones and they are all correct.

However, for class 0:

  • Recall for class 0 will be 0, as no zeros were predicted.
  • Precision for class 0 is undefined (division by zero), as the model did not predict class 0.

Thus, with a strong imbalance and such a strategy, the model appears perfect for the dominant class but completely ignores the minor class. This illustrates that Precision and Recall should be considered separately for each class and that the imbalance should be taken into account. For evaluating models on imbalanced data, metrics that consider both classes, such as F1-score or ROC-AUC, are often used.