Complete the code to import the GradientBoostingClassifier from scikit-learn.
from sklearn.ensemble import [1]
The GradientBoostingClassifier is the correct class to import for gradient boosting classification tasks.
Complete the code to create a GradientBoostingClassifier with 100 trees.
model = GradientBoostingClassifier(n_estimators=[1])The n_estimators parameter sets the number of boosting stages or trees. 100 is a common default value.
Fix the error in the code to fit the model on training data X_train and y_train.
model.[1](X_train, y_train)predict instead of fit to train the model.transform which is for data preprocessing.The fit method trains the model on the given data.
Fill both blanks to create a dictionary of feature importances from the trained model.
feature_importances = {feature: model.[1][index] for index, feature in enumerate([2])}coef_ which is for linear models, not gradient boosting.features which is not a standard variable name.The trained model stores feature importances in feature_importances_. The list of feature names is typically stored in feature_names.
Fill all three blanks to compute accuracy score of the model on test data.
from sklearn.metrics import [1] predictions = model.[2](X_test) accuracy = [3](y_test, predictions)
confusion_matrix instead of accuracy_score for metric.score method instead of using accuracy_score function.We import accuracy_score to measure accuracy. We use predict to get model predictions. Then we compute accuracy by comparing true labels and predictions.