Accuracy is not a great metric for evaluating the performance of machine learning models, especially when the classes are imbalanced. There are several other metrics that can provide a better understanding of how well a model is performing.

Confusion Matrix

The confusion matrix is a table presenting four metrics:

  • True Positives (TP): The number of positive samples correctly classified as positive.
  • True Negatives (TN): The number of negative samples correctly classified as negative.
  • False Positives (FP): The number of negative samples incorrectly classified as positive.
  • False Negatives (FN): The number of positive samples incorrectly classified as negative.
quadrantChart
    title Confusion Matrix
    x-axis Actual Positive --> Actual Negative
    y-axis Predicted Negative --> Predicted Positive
    quadrant-1 False Positives
    quadrant-2 True Positives
    quadrant-3 False Negatives
    quadrant-4 True Negatives

These values can be used to calculate performance metrics such as accuracy, precision, recall, and F1 score.

Accuracy

Accuracy is the ratio of correctly predicted samples to the total number of samples. $$\text{Accuracy} = \frac{TP + TN}{TP + TN + FP + FN}$$

Precision

Precision is the ratio of correctly predicted positive samples to the total number of samples predicted as positive. $$\text{Precision} = \frac{TP}{TP + FP}$$

Recall

Recall is the ratio of correctly predicted positive samples to the total number of positive samples. $$\text{Recall} = \frac{TP}{TP + FN}$$

F1 Score

The F1 score is the harmonic mean of precision and recall. $$\text{F1 Score} = 2 \times \frac{\text{Precision} \times \text{Recall}}{\text{Precision} + \text{Recall}}$$

Specificity

Specificity is the ratio of correctly predicted negative samples to the total number of negative samples. $$\text{Specificity} = \frac{TN}{TN + FP}$$