0
0
ML Pythonml~20 mins

Gradient Boosting for regression in ML Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Gradient Boosting Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
How does Gradient Boosting improve regression predictions?

Imagine you want to predict house prices. Gradient Boosting builds many small models one after another. What is the main way it improves predictions?

AIt randomly selects features to reduce overfitting.
BEach model predicts independently and their results are averaged.
CIt uses a single large model trained once on all data.
DEach new model tries to fix the errors made by all previous models.
Attempts:
2 left
💡 Hint

Think about how mistakes from earlier models guide the next ones.

Predict Output
intermediate
2:00remaining
Output of Gradient Boosting regression training metrics

What will be the printed training loss after 3 iterations of this Gradient Boosting Regressor?

ML Python
from sklearn.datasets import make_regression
from sklearn.ensemble import GradientBoostingRegressor

X, y = make_regression(n_samples=100, n_features=1, noise=5, random_state=42)
model = GradientBoostingRegressor(n_estimators=3, learning_rate=1.0, max_depth=1, random_state=42)
model.fit(X, y)
print(round(model.train_score_[-1], 2))
A0.00
B0.25
C0.12
D0.50
Attempts:
2 left
💡 Hint

Look at how train_score_ stores deviance (loss) after each iteration.

Model Choice
advanced
2:00remaining
Choosing the best base learner for Gradient Boosting regression

You want to use Gradient Boosting to predict a continuous target with complex nonlinear relationships. Which base learner is best to use?

ALinear regression models as base learners
BDecision trees with shallow depth (e.g., max_depth=3)
CSingle-layer perceptrons (simple neural networks)
DK-nearest neighbors as base learners
Attempts:
2 left
💡 Hint

Consider which model type can capture nonlinear patterns well and is commonly used in Gradient Boosting.

Hyperparameter
advanced
2:00remaining
Effect of learning rate in Gradient Boosting regression

What happens if you set the learning rate too high in a Gradient Boosting regression model?

AThe model may overfit and fail to generalize well.
BThe model will train slower but be more accurate.
CThe model will ignore the residuals and not improve.
DThe model will always underfit the training data.
Attempts:
2 left
💡 Hint

Think about how a large step size affects the model updates.

🔧 Debug
expert
2:00remaining
Why does this Gradient Boosting regression model raise a ValueError?

Consider this code snippet:

from sklearn.ensemble import GradientBoostingRegressor
model = GradientBoostingRegressor(n_estimators=100, loss='log_loss')
model.fit(X_train, y_train)

Why does it raise a ValueError?

ABecause 'log_loss' is not a valid loss function for regression tasks.
BBecause n_estimators must be less than 50 for Gradient Boosting.
CBecause GradientBoostingRegressor requires y_train to be categorical.
DBecause the input data X_train is missing.
Attempts:
2 left
💡 Hint

Check the allowed loss functions for regression in Gradient Boosting.