Bird
Raised Fist0
ML Pythonml~20 mins

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

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Ensemble Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why do ensemble models usually perform better than single models?

Imagine you ask several friends for advice instead of just one. Why might their combined advice be better? Similarly, why do ensemble models often outperform a single model?

ABecause ensembles ignore the predictions of weaker models.
BBecause ensembles always use deeper neural networks than single models.
CBecause ensembles train on more data than single models.
DBecause ensembles combine multiple models, reducing errors from individual models and improving overall accuracy.
Attempts:
2 left
💡 Hint

Think about how combining different opinions can reduce mistakes.

Metrics
intermediate
2:00remaining
Effect of ensemble on model variance

You have 5 models each with variance 0.04 and zero covariance between them. What is the variance of the average prediction from these 5 models?

A0.008
B0.04
C0.2
D0.0008
Attempts:
2 left
💡 Hint

Variance of average of independent variables is variance divided by number of variables.

Predict Output
advanced
2:00remaining
Output of ensemble prediction averaging

What is the output of the following Python code that averages predictions from three models?

ML Python
predictions = [[0.2, 0.8], [0.3, 0.7], [0.1, 0.9]]
avg_pred = [sum(x)/len(x) for x in zip(*predictions)]
print([round(p, 2) for p in avg_pred])
A[0.3, 0.7]
B[0.15, 0.85]
C[0.2, 0.8]
D[0.5, 0.5]
Attempts:
2 left
💡 Hint

Calculate average for each class probability across models.

Model Choice
advanced
2:00remaining
Choosing ensemble type for reducing bias and variance

You want to reduce both bias and variance in your model predictions. Which ensemble method is best suited for this?

ASimple averaging of identical models
BBagging (e.g., Random Forest)
CBoosting (e.g., Gradient Boosting Machines)
DUsing a single deep neural network
Attempts:
2 left
💡 Hint

Think about which method focuses on correcting errors and improving weak learners.

🔧 Debug
expert
3:00remaining
Why does this ensemble code produce wrong predictions?

Consider this code that tries to ensemble predictions by majority vote. What is the bug causing incorrect output?

ML Python
import numpy as np
preds = [[1,0,1],[0,1,1],[1,1,0]]
ensemble_pred = [np.argmax(np.bincount(preds)) for i in range(len(preds[0]))]
print(ensemble_pred)
Anp.bincount is called on the whole list instead of per position, causing wrong counts.
BThe list comprehension incorrectly uses i in range(len(preds[0])) causing index errors.
Cnp.bincount is called on a list of predictions per position correctly; no bug here.
Dnp.argmax is used incorrectly; it should be np.argmin to get majority vote.
Attempts:
2 left
💡 Hint

Check what data np.bincount receives inside the list comprehension.

Practice

(1/5)
1. Why do ensemble models usually perform better than a single model?
easy
A. Because they always use deep learning
B. Because they use only one model with more data
C. Because they ignore data variability
D. Because they combine multiple models to reduce errors

Solution

  1. Step 1: Understand ensemble concept

    Ensembles combine predictions from multiple models to reduce individual errors.
  2. Step 2: Compare with single model

    A single model may make mistakes that ensembles can correct by averaging or voting.
  3. Final Answer:

    Because they combine multiple models to reduce errors -> Option D
  4. Quick Check:

    Ensembles reduce errors = A [OK]
Hint: Ensembles mix models to fix mistakes [OK]
Common Mistakes:
  • Thinking ensembles use only one model
  • Believing ensembles ignore data differences
  • Assuming ensembles always use deep learning
2. Which of the following is the correct way to combine predictions in an ensemble?
easy
A. Taking the average or majority vote of multiple models' outputs
B. Using only the prediction of the first model
C. Multiplying all model predictions together
D. Ignoring all predictions and guessing randomly

Solution

  1. Step 1: Identify ensemble combination methods

    Common methods include averaging predictions or majority voting among models.
  2. Step 2: Eliminate incorrect methods

    Using only one model or random guessing does not combine models properly; multiplying predictions is not standard.
  3. Final Answer:

    Taking the average or majority vote of multiple models' outputs -> Option A
  4. Quick Check:

    Average or vote = D [OK]
Hint: Combine by averaging or voting predictions [OK]
Common Mistakes:
  • Using only one model's output
  • Multiplying predictions incorrectly
  • Ignoring ensemble predictions
3. Consider three models with prediction errors of 10%, 12%, and 15%. What is the expected error if we use a simple average ensemble of these models?
medium
A. 37%
B. 15%
C. 12.33%
D. 10%

Solution

  1. Step 1: Calculate average error

    Sum errors: 10% + 12% + 15% = 37%. Divide by 3 models: 37% / 3 = 12.33%.
  2. Step 2: Understand ensemble effect

    Averaging errors reduces overall error compared to the worst single model.
  3. Final Answer:

    12.33% -> Option C
  4. Quick Check:

    Average error = 12.33% [OK]
Hint: Average errors to find ensemble error [OK]
Common Mistakes:
  • Adding errors without dividing
  • Picking highest or lowest error directly
  • Confusing error with accuracy
4. You have an ensemble of 5 models but the combined accuracy is lower than the best single model. What is the most likely reason?
medium
A. The models are too similar and make the same mistakes
B. The ensemble uses majority voting correctly
C. The models have very different errors
D. The ensemble averages predictions properly

Solution

  1. Step 1: Analyze ensemble failure cause

    If models are very similar, they tend to make the same errors, so ensemble gains are lost.
  2. Step 2: Check other options

    Correct voting or averaging usually improves accuracy; different errors help ensemble, so these are unlikely causes.
  3. Final Answer:

    The models are too similar and make the same mistakes -> Option A
  4. Quick Check:

    Similar models cause poor ensemble = A [OK]
Hint: Diverse models improve ensembles, similar hurt [OK]
Common Mistakes:
  • Assuming voting always improves accuracy
  • Ignoring model similarity
  • Thinking averaging can fix identical errors
5. You want to build an ensemble to improve prediction on a noisy dataset. Which strategy best explains why ensembles help in this case?
hard
A. Ignoring noise by removing data points is better than ensembles
B. Combining models averages out noise, reducing variance in predictions
C. Using a single complex model always beats ensembles
D. Ensembles increase noise by combining errors

Solution

  1. Step 1: Understand noise impact on models

    Noisy data causes models to vary in predictions; combining them averages out random errors.
  2. Step 2: Compare strategies

    Single complex models may overfit noise; removing data loses information; ensembles reduce variance by averaging.
  3. Final Answer:

    Combining models averages out noise, reducing variance in predictions -> Option B
  4. Quick Check:

    Ensembles reduce noise variance = C [OK]
Hint: Ensembles smooth noise by averaging predictions [OK]
Common Mistakes:
  • Believing single models always outperform ensembles
  • Thinking ensembles increase noise
  • Ignoring the benefit of averaging noisy predictions