A confusion matrix is like a report card for binary classification models. It is a tool that checks how well a model is performing on a test dataset.
Consider a scenario where the target variable has two categories: Positive or Negative. The confusion matrix, represented as a 2x2 table, shows combinations of predicted and actual values.
The matrix helps us understand the model's performance through terms like TP (True Positive), FP (False Positive), FN (False Negative) and TN (True Negative). These terms describe different situations where the model gets things right or wrong.
TP (True Positive): The predicted value is positive and the actual value is also positive.
FP (False Positive): The predicted value is positive and the actual value is negative.
FN (False Negative): The predicted value is negative and the actual value is positive.
TN (True Negative): The predicted value is negative and the actual value is also negative.
Besides this, a confusion matrix also helps to evaluate other important metrics related to a classification model:
Accuracy: How many predictions are correct out of all predictions?
Precision: Out of the things predicted as positive, how many are actually positive? Useful when mistaking something as positive is a bigger concern than missing it.
Recall: Out of all the actual positive cases, how many did our model catch? Important in cases where missing a positive thing is more serious than mistakenly flagging something as positive.
F1 Score: A balance between precision and recall. It gives an overall rating of how well the model is doing.