Challenge - 5 Problems
Classification Report Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of classification report with imbalanced classes
Given a binary classification with true labels and predicted labels as below, what is the precision for class 1 in the classification report?
TensorFlow
from sklearn.metrics import classification_report y_true = [0, 0, 0, 1, 1, 1, 1] y_pred = [0, 0, 1, 1, 0, 1, 1] report = classification_report(y_true, y_pred, output_dict=True) precision_class_1 = report['1']['precision'] print(round(precision_class_1, 2))
Attempts:
2 left
💡 Hint
Precision is the ratio of true positives to all predicted positives for that class.
✗ Incorrect
Precision for class 1 is calculated as TP / (TP + FP). Here, TP=3 (correctly predicted 1s), FP=1 (predicted 1 but true label 0), so precision = 3/(3+1) = 0.75. The code prints round(0.75, 2) = 0.75 (option D).
❓ Model Choice
intermediate1:30remaining
Choosing the right metric for multi-class classification
You have a multi-class classification problem with 5 classes and want to evaluate your TensorFlow model. Which metric from the classification report best shows the balance between precision and recall for each class?
Attempts:
2 left
💡 Hint
Think about a metric that combines precision and recall.
✗ Incorrect
F1-score is the harmonic mean of precision and recall, showing a balance between the two. It is especially useful when you want to consider both false positives and false negatives.
❓ Hyperparameter
advanced2:00remaining
Effect of threshold on classification report metrics
In a binary classification TensorFlow model, you adjust the decision threshold from 0.5 to 0.7. How does this change most likely affect the precision and recall for the positive class in the classification report?
Attempts:
2 left
💡 Hint
Raising the threshold makes the model more strict about positive predictions.
✗ Incorrect
Increasing the threshold means fewer positive predictions, so false positives reduce, increasing precision. But some true positives are missed, lowering recall.
🔧 Debug
advanced2:00remaining
Debugging unexpected classification report output
You run classification_report on your TensorFlow model predictions but see all zeros for precision, recall, and f1-score for one class. What is the most likely cause?
TensorFlow
from sklearn.metrics import classification_report true_labels = [0, 1, 2, 2, 1] pred_labels = [0, 0, 2, 2, 0] print(classification_report(true_labels, pred_labels))
Attempts:
2 left
💡 Hint
Check if the model predicted any samples for that class.
✗ Incorrect
If the model never predicts a class, precision and recall for that class become zero because there are no true positives or predicted positives, leading to zero metrics.
🧠 Conceptual
expert2:30remaining
Interpreting macro vs weighted averages in classification reports
In a multi-class classification report, what is the key difference between macro average and weighted average for precision, recall, and F1-score?
Attempts:
2 left
💡 Hint
Think about how class size affects the averaging.
✗ Incorrect
Macro average treats all classes equally regardless of size, while weighted average accounts for the number of true instances per class, giving more influence to larger classes.