Bird
0
0

This code tries to combine rule and ML outputs but has a bug:

medium📝 Debug Q14 of 15
NLP - Sentiment Analysis Advanced
This code tries to combine rule and ML outputs but has a bug:
rule_pred = [True, False, True]
ml_pred = [False, False, True]
combined = [r and m for r, m in zip(rule_pred, ml_pred)]
print(combined)
What is the bug and how to fix it?
ABug: Using AND drops some positives; fix by using OR instead.
BBug: Lists have different lengths; fix by padding shorter list.
CBug: Using booleans instead of integers; fix by casting to int.
DBug: zip is incorrect; fix by using enumerate instead.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the logical operation used

    The code uses AND, which requires both to be True to get True.
  2. Step 2: Identify why this causes a problem

    AND drops positives where only one prediction is True, losing some correct results.
  3. Step 3: Suggest fix

    Using OR keeps positives if either prediction is True, improving recall.
  4. Final Answer:

    Bug: Using AND drops some positives; fix by using OR instead. -> Option A
  5. Quick Check:

    AND drops positives; OR fixes [OK]
Quick Trick: Use OR to keep positives from either source [OK]
Common Mistakes:
MISTAKES
  • Thinking zip causes error
  • Confusing booleans with integers
  • Ignoring logical operation impact

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes