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機器學習》學習筆記