0
0
ML Pythonml~10 mins

XGBoost 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 XGBoost classifier.

ML Python
from xgboost import [1]
Drag options to blanks, or click blank then click option'
AXGBClassifier
BXGBRegressor
CXGBModel
DXGBTree
Attempts:
3 left
💡 Hint
Common Mistakes
Using XGBRegressor which is for regression tasks.
Trying to import a non-existent class like XGBTree.
2fill in blank
medium

Complete the code to create an XGBoost classifier with 100 trees.

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

Fix the error in the code to train the model on features X and labels y.

ML Python
model.fit([1], y)
Drag options to blanks, or click blank then click option'
Amodel
Bfeatures
CX
Dy
Attempts:
3 left
💡 Hint
Common Mistakes
Passing labels y as the first argument instead of features.
Passing the model itself or an undefined variable.
4fill in blank
hard

Fill both blanks to predict labels and calculate accuracy score.

ML Python
preds = model.[1](X_test)
accuracy = [2](y_test, preds)
Drag options to blanks, or click blank then click option'
Apredict
Baccuracy_score
Cfit
Dscore
Attempts:
3 left
💡 Hint
Common Mistakes
Using fit instead of predict to get predictions.
Using score method instead of accuracy_score function.
5fill in blank
hard

Fill all three blanks to create a dictionary of feature importances for features in feature_names.

ML Python
importances = { [1]: model.feature_importances_[i] for i, [2] in enumerate([3]) }
Drag options to blanks, or click blank then click option'
Afeature
Bname
Cfeature_names
Dindex
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping variable names in the loop.
Using wrong variable for the list of feature names.