A confusion matrix evaluates a classification model by cross-tabulating actual labels against predicted labels. For binary classification, it records true positives, true negatives, false positives, and false negatives, separating correct predictions from each type of error. section 5.2.4 section 6.3.4
Read the four cells as follows:
- True positive (TP): actual class 1 and predicted class 1. section 6.3.4
- True negative (TN): actual class 0 and predicted class 0. section 6.3.4
- False positive (FP): actual class 0 but predicted class 1. section 6.3.4
- False negative (FN): actual class 1 but predicted class 0. section 6.3.4
Constructing and interpreting a matrix
With pandas, `pd.crosstab(raisins_subset['Class'], raisins_subset['prediction'])` produces [[397, 53], [66, 384]]. Thus TN = 397, FP = 53, FN = 66, and TP = 384. These counts yield 85.33% sensitivity, 88.22% specificity, 86.78% accuracy, and 13.22% misclassification. section 5.2.4
Table 5.1 Confusion matrix for raisin classification. A confusion matrix stores classification metrics from a regression with actual and predicted binary outcomes.
|
Predicted
|
|||
|---|---|---|---|
|
Kecimen (0)
|
Besni (1)
|
||
|
Actual
|
Kecimen (0)
|
tn
|
fp
|
|
Besni (1)
|
fn
|
tp
|
|
Use the table to trace actual classes by row and predicted classes by column, then identify each error type. section 5.2.4













