Understand the idea
Rows represent actual classes and columns predicted classes when using sklearn confusion_matrix. Explicit label order prevents accidental relabelling.
What the syntax does
confusion_matrix- Counts actual/predicted class pairs; rows are actual classes and columns are
predictedclasses.
- Counts actual/predicted class pairs; rows are actual classes and columns are
labels=['A','B']- Fixes both axis orders, including a class with zero predictions.
Outputs you create
answer- The requested result, with the values, labels and row order described by this task.
actual | predicted |
|---|---|
| A | A |
| A | A |
| A | A |
| A | A |
| A | A |
| A | A |
| A | A |
| A | B |
| B | A |
| B | A |
| B | A |
| B | B |
Your task
- Build the A/B confusion matrix from ERROR12.
answerHints
Think: Matrix rows and columns have different meanings and need an explicit class order.
Tools: confusion_matrix with labels.
Approach: Pass actual labels first, predictions second and supply the requested A/B order.
Explained solution
from sklearn.metrics import confusion_matrix
answer=confusion_matrix(df.actual,df.predicted,labels=['A','B'])
An explicit order keeps true-class and predicted-class counts interpretable even when frequencies differ.