我基于此在数据框中完成了一个功能选择:https://towardsdatascience.com/feature-selection-using-random-forest-26d7b747597f
在第7部分,为了描绘重要性的分布,……
pd.Series(sel.estimator_.feature_importances_.ravel()).hist()
这是“系列”不是“系列”
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.hist.html
importances = sel.estimator_.feature_importances_ indices = np.argsort(importances)[::-1] # X is the train data used to fit the model plt.figure() plt.title("Feature importances") plt.bar(range(X.shape[1]), importances[indices], color="r", align="center") plt.xticks(range(X.shape[1]), indices) plt.xlim([-1, X.shape[1]]) plt.show()
这应该呈现如下的条形图,其中x轴是特征索引,y轴是特征重要性。功能按重要性顺序排序。