0
0
TensorFlowml~20 mins

Confusion matrix analysis in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Confusion Matrix Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Confusion matrix shape from TensorFlow predictions
Given a binary classification model in TensorFlow, what is the shape of the confusion matrix returned by tf.math.confusion_matrix when comparing true labels and predicted labels?
TensorFlow
import tensorflow as tf
true_labels = tf.constant([0, 1, 0, 1, 1])
pred_labels = tf.constant([0, 0, 0, 1, 1])
cm = tf.math.confusion_matrix(true_labels, pred_labels)
cm_shape = cm.shape
print(cm_shape)
A(1, 2)
B(5, 5)
C(3, 3)
D(2, 2)
Attempts:
2 left
💡 Hint
The confusion matrix size depends on the number of classes, not the number of samples.
Metrics
intermediate
2:00remaining
Calculating accuracy from confusion matrix
Given the confusion matrix below, what is the accuracy of the model? [[50, 10], [5, 35]]
A0.80
B0.85
C0.90
D0.75
Attempts:
2 left
💡 Hint
Accuracy = (True Positives + True Negatives) / Total samples
Model Choice
advanced
2:00remaining
Choosing model type based on confusion matrix imbalance
You have a confusion matrix with many false negatives but few false positives. Which model adjustment is best to reduce false negatives?
AIncrease recall by adjusting the classification threshold lower
BIncrease precision by adjusting the classification threshold higher
CUse a simpler model to reduce overfitting
DUse early stopping during training
Attempts:
2 left
💡 Hint
Recall focuses on reducing false negatives.
🔧 Debug
advanced
2:00remaining
Identifying error in confusion matrix calculation code
What error will this TensorFlow code raise? import tensorflow as tf true = tf.constant([0, 1, 2]) pred = tf.constant([0, 1]) cm = tf.math.confusion_matrix(true, pred) print(cm)
TensorFlow
import tensorflow as tf
true = tf.constant([0, 1, 2])
pred = tf.constant([0, 1])
cm = tf.math.confusion_matrix(true, pred)
print(cm)
AValueError due to invalid label values
BTypeError due to wrong input types
CInvalidArgumentError due to shape mismatch
DNo error, prints confusion matrix
Attempts:
2 left
💡 Hint
True and predicted labels must have the same length.
🧠 Conceptual
expert
3:00remaining
Interpreting confusion matrix for multi-class classification
In a 3-class classification problem, the confusion matrix is: [[30, 2, 3], [4, 25, 1], [5, 0, 35]] Which class has the highest precision?
AClass 1
BClass 2
CClass 0
DAll classes have equal precision
Attempts:
2 left
💡 Hint
Precision = True Positives / (True Positives + False Positives) for each class.