0
0
ML Pythonml~10 mins

Gradient Boosting for regression in ML Python - Interactive Code Practice

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

Complete the code to import the GradientBoostingRegressor from scikit-learn.

ML Python
from sklearn.ensemble import [1]
Drag options to blanks, or click blank then click option'
ARandomForestRegressor
BGradientBoostingRegressor
CLinearRegression
DKNeighborsRegressor
Attempts:
3 left
💡 Hint
Common Mistakes
Importing a classifier instead of a regressor.
Importing a different ensemble model like RandomForestRegressor.
2fill in blank
medium

Complete the code to create a Gradient Boosting regressor with 100 trees.

ML Python
model = GradientBoostingRegressor(n_estimators=[1])
Drag options to blanks, or click blank then click option'
A100
B10
C1000
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using too few trees like 1 or 10 which may underfit.
Using too many trees like 1000 which may be slow to train.
3fill in blank
hard

Fix the error in the code to fit the model on training data X_train and y_train.

ML Python
model.[1](X_train, y_train)
Drag options to blanks, or click blank then click option'
Afit
Bpredict
Ctransform
Dscore
Attempts:
3 left
💡 Hint
Common Mistakes
Calling predict before fitting the model.
Using transform which is for data preprocessing.
4fill in blank
hard

Fill both blanks to compute the mean squared error between true and predicted values.

ML Python
from sklearn.metrics import [1]
error = [2](y_true, y_pred)
Drag options to blanks, or click blank then click option'
Amean_squared_error
Baccuracy_score
Cmean_absolute_error
Dr2_score
Attempts:
3 left
💡 Hint
Common Mistakes
Using accuracy_score which is for classification.
Using mean_absolute_error which measures absolute errors, not squared.
5fill in blank
hard

Fill all three blanks to create a Gradient Boosting regressor with learning rate 0.1, max depth 3, and fit it on data.

ML Python
model = GradientBoostingRegressor(learning_rate=[1], max_depth=[2])
model.[3](X_train, y_train)
Drag options to blanks, or click blank then click option'
A0.1
B3
Cfit
Dpredict
Attempts:
3 left
💡 Hint
Common Mistakes
Using predict instead of fit to train the model.
Setting max_depth too high or learning_rate too large.