from sklearn.ensemble import RandomForestClassifier
feat_labels = X.columns[0:]
forest = RandomForestClassifier(n_estimators=10000,
random_state=0,
n_jobs=-1)
forest.fit(X_train,y_train)
importances = forest.feature_importances_
indices = np.argsort(importances)[::-1]
for f in range(X_train.shape[1]):
print(feat_labels[f],importances[indices[f]])
结果以“特征:重要性”的形式显示出来
《python机器学习》学习笔记