Which part of the confusion matrix represents the number of times the model correctly predicted the positive class?
Think about when the model predicts positive and the actual label is also positive.
True Positive (TP) counts the cases where the model correctly predicts the positive class.
What is the output of the following Python code that computes a confusion matrix?
from sklearn.metrics import confusion_matrix true_labels = [1, 0, 1, 1, 0, 0, 1] pred_labels = [1, 0, 0, 1, 0, 1, 1] cm = confusion_matrix(true_labels, pred_labels) print(cm.tolist())
Count how many times each true label matches predicted label and mismatches.
The confusion matrix rows represent true labels and columns predicted labels. Here, [[2,1],[1,3]] means 2 true negatives, 1 false positive, 1 false negative, and 3 true positives.
Given a confusion matrix [[50, 10], [5, 35]], what is the accuracy of the model?
Accuracy = (TP + TN) / Total samples.
Accuracy = (50 + 35) / (50 + 10 + 5 + 35) = 85 / 100 = 0.85.
What error will the following code raise?
from sklearn.metrics import confusion_matrix true = [1, 0, 1] pred = [1, 0] cm = confusion_matrix(true, pred) print(cm)
Check if true and predicted label lists have the same length.
The true and predicted label lists have different lengths, causing a ValueError about inconsistent sample numbers.
You have a dataset with 95% negative and 5% positive samples. Which confusion matrix derived metric is best to evaluate your model's ability to detect positives?
Think about which metric focuses on catching positive cases even if they are rare.
Recall measures how many actual positives the model correctly identifies, which is crucial for imbalanced data where positives are rare.
