Complete the code to import the RandomForestClassifier from scikit-learn.
from sklearn.ensemble import [1]
The RandomForestClassifier is the correct class to import for building a random forest model for classification tasks.
Complete the code to create a random forest model with 100 trees.
model = RandomForestClassifier(n_estimators=[1])The n_estimators parameter sets the number of trees in the forest. 100 is a common choice for good performance.
Fix the error in the code to fit the model on training data X_train and y_train.
model.[1](X_train, y_train)The fit method trains the model on the given data. Using predict or transform here would cause errors.
Fill both blanks to create a dictionary of feature importances and sort it by importance descending.
importances = dict(enumerate(model.[1])) sorted_importances = dict(sorted(importances.items(), key=lambda item: item[[2]], reverse=True))
feature_importances_ is the attribute holding importance scores. Sorting by item[1] sorts by the importance value.
Fill all three blanks to predict on test data X_test, calculate accuracy, and print it.
predictions = model.[1](X_test) accuracy = [2](y_test, predictions) print('Accuracy:', [3])
Use predict to get predictions, accuracy_score to calculate accuracy, and print the accuracy variable.