Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the XGBoost classifier.
ML Python
from xgboost import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using XGBRegressor which is for regression tasks.
Trying to import a non-existent class like XGBTree.
✗ Incorrect
The XGBClassifier is the class used for classification tasks in XGBoost.
2fill in blank
mediumComplete 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'
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.
✗ Incorrect
The n_estimators parameter sets the number of trees. 100 is a common choice.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing labels y as the first argument instead of features.
Passing the model itself or an undefined variable.
✗ Incorrect
The fit method requires the feature data X as the first argument.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using fit instead of predict to get predictions.
Using score method instead of accuracy_score function.
✗ Incorrect
Use predict to get predictions and accuracy_score to measure accuracy.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping variable names in the loop.
Using wrong variable for the list of feature names.
✗ Incorrect
Use name as the key, feature as the loop variable, and feature_names as the list of features.