response = 'y'
X = df[predictors]
y = df[response]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
clf = RandomForestClassifier(max_features=5)
clf.fit(X_train.values, y_train.values)
importances = pd.DataFrame({'feature': X_train.columns, 'importance': np.
    round(clf.feature_importances_, 3)})
importances = importances.sort_values('importance', ascending=False).set_index(
    'feature')
print(importances)
importances.plot.bar()
How does sklearn random forest index feature_importances_