A confusion matrix is a table that shows how well a classification model performs by comparing actual labels with predicted labels. It helps us see where the model makes correct and wrong predictions.
Click to reveal answer
beginner
What do the terms True Positive (TP), False Positive (FP), True Negative (TN), and False Negative (FN) mean in a confusion matrix?
TP: Model correctly predicts positive. FP: Model wrongly predicts positive. TN: Model correctly predicts negative. FN: Model wrongly predicts negative.
Click to reveal answer
beginner
How do you calculate accuracy from a confusion matrix?
Accuracy = (TP + TN) / (TP + TN + FP + FN). It shows the overall correctness of the model's predictions.
Click to reveal answer
intermediate
What is precision and why is it important?
Precision = TP / (TP + FP). It tells us how many of the predicted positives are actually correct. Important when false positives are costly.
Click to reveal answer
intermediate
How can you compute a confusion matrix using TensorFlow?
Use tf.math.confusion_matrix(labels, predictions) where labels are true classes and predictions are predicted classes. It returns a matrix showing counts of all classes, not specifically TP, FP, TN, FN.
Click to reveal answer
What does a high number of False Negatives (FN) indicate?
AModel misses many positive cases
BModel predicts too many positives
CModel predicts negatives correctly
DModel has high precision
✗ Incorrect
False Negatives mean the model predicted negative when the true label was positive, so it misses positive cases.
Which metric is calculated as TP / (TP + FP)?
ARecall
BAccuracy
CF1 Score
DPrecision
✗ Incorrect
Precision measures how many predicted positives are actually positive.
In TensorFlow, which function computes the confusion matrix?
Atf.math.confusion_matrix()
Btf.metrics.confusion_matrix()
Ctf.confusion_matrix()
Dtf.linalg.confusion_matrix()
✗ Incorrect
tf.math.confusion_matrix() is the correct TensorFlow function to compute confusion matrices.
What does the diagonal of a confusion matrix represent?
AWrong predictions
BFalse negatives
CCorrect predictions
DFalse positives
✗ Incorrect
The diagonal entries show counts where predicted labels match true labels, meaning correct predictions.
Which metric is best to use when false positives are very costly?
ARecall
BPrecision
CAccuracy
DLoss
✗ Incorrect
Precision focuses on reducing false positives, so it is important when false positives are costly.
Explain what a confusion matrix is and how it helps evaluate a classification model.
Think about how you check if your model guesses right or wrong.
You got /3 concepts.
Describe how to compute precision and recall from a confusion matrix and when each is important.
Precision is about correct positive predictions; recall is about finding all positives.
You got /3 concepts.
Practice
(1/5)
1. What does a confusion matrix primarily show in a classification problem?
easy
A. The number of correct and incorrect predictions for each class
B. The training time of the model
C. The number of features used in the model
D. The learning rate of the optimizer
Solution
Step 1: Understand the purpose of a confusion matrix
A confusion matrix displays how many predictions were correct or wrong for each class in classification.
Step 2: Compare options with the definition
Only The number of correct and incorrect predictions for each class correctly describes this purpose; others relate to unrelated model aspects.
Final Answer:
The number of correct and incorrect predictions for each class -> Option A
Quick Check:
Confusion matrix = correct/wrong counts [OK]
Hint: Confusion matrix counts correct vs wrong predictions per class [OK]
Common Mistakes:
Confusing confusion matrix with training metrics like loss
Thinking it shows model parameters
Assuming it shows training time
2. Which TensorFlow function is used to compute a confusion matrix from true labels and predicted labels?
easy
A. tf.data.Dataset.from_tensor_slices()
B. tf.keras.metrics.Accuracy()
C. tf.math.confusion_matrix()
D. tf.nn.softmax()
Solution
Step 1: Identify TensorFlow functions related to confusion matrix
The function tf.math.confusion_matrix() directly computes the confusion matrix from labels.