0
0
ML Pythonml~10 mins

Gradient Boosting (GBM) 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 GradientBoostingClassifier from scikit-learn.

ML Python
from sklearn.ensemble import [1]
Drag options to blanks, or click blank then click option'
ALogisticRegression
BRandomForestClassifier
CKNeighborsClassifier
DGradientBoostingClassifier
Attempts:
3 left
💡 Hint
Common Mistakes
Importing a different classifier like RandomForestClassifier by mistake.
Confusing GradientBoostingClassifier with LogisticRegression.
2fill in blank
medium

Complete the code to create a GradientBoostingClassifier with 100 trees.

ML Python
model = GradientBoostingClassifier(n_estimators=[1])
Drag options to blanks, or click blank then click option'
A10
B100
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
Using predict instead of fit to train the model.
Using transform which is for data preprocessing.
4fill in blank
hard

Fill both blanks to create a dictionary of feature importances from the trained model.

ML Python
feature_importances = {feature: model.[1][index] for index, feature in enumerate([2])}
Drag options to blanks, or click blank then click option'
Afeature_importances_
Bfeature_names
Cfeatures
Dcoef_
Attempts:
3 left
💡 Hint
Common Mistakes
Using coef_ which is for linear models, not gradient boosting.
Using features which is not a standard variable name.
5fill in blank
hard

Fill all three blanks to compute accuracy score of the model on test data.

ML Python
from sklearn.metrics import [1]
predictions = model.[2](X_test)
accuracy = [3](y_test, predictions)
Drag options to blanks, or click blank then click option'
Aaccuracy_score
Bpredict
Dconfusion_matrix
Attempts:
3 left
💡 Hint
Common Mistakes
Using confusion_matrix instead of accuracy_score for metric.
Calling score method instead of using accuracy_score function.