A confusion matrix is a table that summarizes the predictive performance of a classification model. It presents the number of true positives (TP), false positives (FP), true negatives (TN), and false negatives (FN) in a matrix format. Here’s what it looks like:
$$\begin{array}{|c|c|c|}
\hline
&\text{Actual Positive}&\text{Actual Negative}\\\hline
\text{Predicted Positive}&\text{True Positive (TP)}&\text{False Positive (FP)}\\\hline
\text{Predicted Negative}&\text{False Negative (FN)}&\text{True Negative (TN)}\\\hline
\end{array}$$
Each cell of the matrix represents a classification outcome. The rows represent the actual classes, while the columns represent the predicted classes.
The confusion matrix helps us to evaluate the performance of a classification model by calculating various metrics, such as accuracy, precision, recall, and F1-score.
Accuracy is the ratio of correctly classified observations to the total number of observations:
$$\text{Accuracy} = \frac{\text{TP}+\text{TN}}{\text{TP}+\text{FP}+\text{TN}+\text{FN}}$$
Precision measures the proportion of predicted positives that are actually true positives:
$$\text{Precision} = \frac{\text{TP}}{\text{TP}+\text{FP}}$$
Recall, also known as sensitivity or true positive rate, measures the proportion of actual positives that are correctly identified as positive:
$$\text{Recall} = \frac{\text{TP}}{\text{TP}+\text{FN}}$$
The F1-score is the harmonic mean of precision and recall:
$$\text{F1-score} = 2*\frac{\text{Precision}*\text{Recall}}{\text{Precision}+\text{Recall}}$$
In general, a good classification model will have high values of accuracy, precision, recall, and F1-score. However, depending on the problem domain, we may prioritize different metrics over others. For example, in medical diagnosis, we may prioritize recall over precision to avoid missing any positive cases.