A. KeyError because 'group3' does not exist; fix by checking keys first
B. SyntaxError due to missing colon; fix by adding colon
C. TypeError because accuracy is not a number; fix by converting to float
D. No error; code runs fine
Solution
Step 1: Identify the error cause
The code accesses metrics['group3'], which is not in the dictionary, causing a KeyError.
Step 2: Suggest fix
Check if 'group3' exists in metrics before accessing or handle missing keys to avoid error.
Final Answer:
KeyError because 'group3' does not exist; fix by checking keys first -> Option A
Quick Check:
Missing key access = KeyError [OK]
Hint: Check dictionary keys before access to avoid KeyError [OK]
Common Mistakes:
Assuming all keys exist without checking
Confusing KeyError with SyntaxError or TypeError
5. You have an NLP sentiment model that predicts positive or negative sentiment. You notice it predicts positive sentiment 90% for group A but only 60% for group B, though both groups have similar real sentiment. What is the best way to improve fairness?
hard
A. Collect more balanced training data including both groups equally
B. Increase model size to improve overall accuracy
C. Use a faster optimizer to train the model
D. Remove group B data from training to avoid confusion
Solution
Step 1: Understand the fairness problem
The model predicts differently for groups with similar real sentiment, indicating bias likely from unbalanced data.
Step 2: Choose the best fix
Collecting balanced data ensures the model learns equally from both groups, improving fairness.
Final Answer:
Collect more balanced training data including both groups equally -> Option A
Quick Check:
Balanced data improves fairness [OK]
Hint: Balanced data helps fix bias in predictions [OK]
Common Mistakes:
Thinking bigger models fix bias automatically
Ignoring data imbalance as cause of unfairness
Removing data from minority groups
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.