from sklearn.tree import DecisionTreeClassifierfrom adspy_shared_utilities import plot_feature_importancestree=DecisionTreeClassifier(random_state=0) tree.fit(X_train2,y_train2)list(X_mush.columns[tree.feature_importances_.argsort()[::-1][0:5]])
- 训练的决策树模型为tree,返回决策树训练的前五个重要特征的list
- 返回排序的索引用argsort函数,函数用法见https://docs.scipy.org/doc/numpy/reference/generated/numpy.argsort.html#numpy.argsort
- 取倒数5个字符用了[::-1][0:5]这样的索引