Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to combine rule-based and machine learning predictions.
NLP
final_prediction = ml_model.predict(data) if [1] else rule_based_predict(data)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'use_rule' instead of 'use_ml' causes the rule-based method to always run.
Using 'use_data' is incorrect because it does not control the prediction method.
✗ Incorrect
The variable 'use_ml' controls whether to use the machine learning model's prediction or the rule-based method.
2fill in blank
mediumComplete the code to merge predictions from ML and rules by averaging.
NLP
combined_score = (ml_score + [1]) / 2
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'ml_prediction' duplicates the ML score instead of combining with rules.
Using 'data_score' is unrelated to rule-based predictions.
✗ Incorrect
We average the machine learning score and the rule-based score to get a combined score.
3fill in blank
hardFix the error in the hybrid prediction function by filling the blank.
NLP
def hybrid_predict(data): if data['length'] > 10: return ml_model.predict(data) else: return [1](data)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling 'ml_model.predict' again ignores the rule-based fallback.
Using 'predict_rule' is not defined and causes an error.
✗ Incorrect
The else branch should call the rule-based prediction function named 'rule_based_predict'.
4fill in blank
hardFill both blanks to create a dictionary of predictions from ML and rules.
NLP
predictions = {
'ml': ml_model.[1](data),
'rule': [2](data)
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'predict_rule' causes a NameError.
Using 'predict_ml' is not a valid method.
✗ Incorrect
The ML model uses 'predict' method, and the rule-based function is 'rule_based_predict'.
5fill in blank
hardFill all three blanks to filter data, predict with ML, and combine with rules.
NLP
filtered_data = [d for d in dataset if d['score'] [1] 0.5] ml_preds = [ml_model.[2](d) for d in filtered_data] final_preds = [ml + [3](d) for ml, d in zip(ml_preds, filtered_data)]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' filters wrong data subset.
Using 'predict_rule' instead of 'rule_based_predict' causes errors.
✗ Incorrect
We filter data with '>', predict with ML using 'predict', and add rule-based predictions using 'rule_based_predict'.