0
0
ML Pythonml~10 mins

Why ensembles outperform single models in ML Python - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a simple ensemble by averaging predictions from two models.

ML Python
ensemble_prediction = (model1.predict(X) [1] model2.predict(X)) / 2
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
2fill in blank
medium

Complete the code to calculate the accuracy of an ensemble model's predictions.

ML Python
accuracy = sum(ensemble_preds == y_true) [1] len(y_true)
Drag options to blanks, or click blank then click option'
A-
B*
C+
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication or addition instead of division.
3fill in blank
hard

Fix the error in the code to combine predictions from three models using majority voting.

ML Python
final_preds = (model1_preds + model2_preds + [1]) >= 2
Drag options to blanks, or click blank then click option'
Amodel3_preds
Bmodel3_pred
Cmodel_3_preds
Dmodel3
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect variable names causing NameError.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that stores model errors only if error is less than 0.1.

ML Python
errors = {model: error[1] for model, error in model_errors.items() if error [2] 0.1}
Drag options to blanks, or click blank then click option'
A* 100
B>
C<
D+ 0.05
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators or forgetting to convert error to percentage.
5fill in blank
hard

Fill all three blanks to create a list comprehension that selects predictions from models with accuracy above 0.8.

ML Python
selected_preds = [preds for model, preds in all_model_preds.items() if accuracies[[1]] [2] [3]]
Drag options to blanks, or click blank then click option'
Amodel
B>
C0.8
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operator or wrong key for accuracies.