Bird
Raised Fist0
TensorFlowml~20 mins

Classification reports in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Classification Report Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2: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))
A0.60
B0.67
C0.80
D0.75
Attempts:
2 left
💡 Hint
Precision is the ratio of true positives to all predicted positives for that class.
❓ Model Choice
intermediate
1: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?
AAccuracy
BF1-score
CPrecision
DRecall
Attempts:
2 left
💡 Hint
Think about a metric that combines precision and recall.
❓ Hyperparameter
advanced
2: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?
APrecision increases, recall decreases
BPrecision decreases, recall increases
CBoth precision and recall increase
DBoth precision and recall decrease
Attempts:
2 left
💡 Hint
Raising the threshold makes the model more strict about positive predictions.
🔧 Debug
advanced
2: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))
AThe model never predicted that class, causing zero division in metrics
BThe true labels are missing that class, so metrics are zero
CThe classification_report function is not compatible with TensorFlow
DThe labels are not integers, causing metric calculation errors
Attempts:
2 left
💡 Hint
Check if the model predicted any samples for that class.
🧠 Conceptual
expert
2: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?
ABoth macro and weighted averages weight metrics by class frequency
BMacro average weights metrics by class support; weighted average averages equally
CMacro average calculates metrics per class and averages equally; weighted average weights by class support
DMacro average only considers the largest class; weighted average considers all classes
Attempts:
2 left
💡 Hint
Think about how class size affects the averaging.

Practice

(1/5)
1. What does a classification report in TensorFlow typically show?
easy
A. Precision, recall, and F1-score for each class
B. The model's training time
C. The number of layers in the model
D. The size of the input data

Solution

  1. Step 1: Understand classification report contents

    A classification report summarizes key metrics like precision, recall, and F1-score for each class predicted by the model.
  2. Step 2: Identify what is NOT included

    Training time, model layers, and input size are not part of the classification report.
  3. Final Answer:

    Precision, recall, and F1-score for each class -> Option A
  4. Quick Check:

    Classification report = precision, recall, F1-score [OK]
Hint: Look for metrics per class, not model structure or time [OK]
Common Mistakes:
  • Confusing training time with performance metrics
  • Thinking model architecture details are in the report
  • Assuming input data size is shown
2. Which code snippet correctly imports the function to generate a classification report in TensorFlow's ecosystem?
easy
A. import classification_report from tensorflow
B. import tensorflow.classification_report as cr
C. from sklearn.metrics import classification_report
D. from tensorflow.metrics import classification_report

Solution

  1. Step 1: Recall the source of classification_report

    The classification_report function is part of scikit-learn, not TensorFlow directly.
  2. Step 2: Check import syntax correctness

    from sklearn.metrics import classification_report uses correct Python import syntax from sklearn.metrics. Other options are invalid or incorrect.
  3. Final Answer:

    from sklearn.metrics import classification_report -> Option C
  4. Quick Check:

    Import classification_report from sklearn.metrics [OK]
Hint: classification_report is from sklearn, not tensorflow [OK]
Common Mistakes:
  • Trying to import classification_report directly from tensorflow
  • Using incorrect import syntax
  • Confusing TensorFlow metrics with sklearn metrics
3. Given the following code, what will be the printed output?
from sklearn.metrics import classification_report
true_labels = [0, 1, 0, 1]
pred_labels = [0, 0, 0, 1]
print(classification_report(true_labels, pred_labels))
medium
A. Empty output with no metrics
B. A report showing precision, recall, and F1-score for classes 0 and 1
C. An error because labels are integers
D. Only accuracy score printed

Solution

  1. Step 1: Understand input labels and predictions

    Labels are valid integers representing two classes: 0 and 1. Predictions have one mistake at index 1.
  2. Step 2: What classification_report prints

    The function prints precision, recall, F1-score, and support for each class, not just accuracy or errors.
  3. Final Answer:

    A report showing precision, recall, and F1-score for classes 0 and 1 -> Option B
  4. Quick Check:

    classification_report outputs metrics per class [OK]
Hint: classification_report prints detailed metrics, not just accuracy [OK]
Common Mistakes:
  • Expecting an error due to integer labels
  • Thinking only accuracy is printed
  • Assuming no output if predictions differ
4. Identify the error in this code snippet that tries to print a classification report:
from sklearn.metrics import classification_report
true = [1, 0, 1]
pred = [1, 0]
print(classification_report(true, pred))
medium
A. print statement syntax is wrong
B. classification_report is not imported correctly
C. Labels must be strings, not integers
D. The true and pred lists have different lengths

Solution

  1. Step 1: Check input list lengths

    True labels list has 3 elements, predicted labels list has 2 elements. They must be the same length.
  2. Step 2: Verify other code parts

    Import and print syntax are correct. Labels can be integers.
  3. Final Answer:

    The true and pred lists have different lengths -> Option D
  4. Quick Check:

    Input lists must match in length [OK]
Hint: Check if true and predicted label lists have same length [OK]
Common Mistakes:
  • Ignoring length mismatch
  • Thinking labels must be strings
  • Assuming import or print is wrong
5. You trained a TensorFlow model for 3 classes: cat, dog, and rabbit. After predictions, you get this classification report:
              precision    recall  f1-score   support

         cat       0.90      0.95      0.92       100
         dog       0.70      0.60      0.65       100
      rabbit       0.50      0.40      0.44       100

    accuracy                           0.68       300
   macro avg       0.70      0.65      0.67       300
weighted avg       0.70      0.68      0.68       300
What should you focus on to improve your model?
hard
A. Improve the model's performance on the rabbit class
B. Increase the support for the cat class
C. Reduce the number of classes
D. Ignore the dog class since it has moderate scores

Solution

  1. Step 1: Analyze class-wise metrics

    Rabbit class has the lowest precision (0.50), recall (0.40), and F1-score (0.44), indicating poor performance.
  2. Step 2: Decide improvement focus

    Improving rabbit predictions will raise overall accuracy and balance. Increasing support or ignoring classes is not helpful.
  3. Final Answer:

    Improve the model's performance on the rabbit class -> Option A
  4. Quick Check:

    Lowest metrics class needs improvement [OK]
Hint: Focus on class with lowest F1-score to improve model [OK]
Common Mistakes:
  • Trying to increase support instead of improving metrics
  • Ignoring poorly performing classes
  • Reducing classes without reason
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard