我已基于此在数据框中进行了特征选择: https://towardsdatascience.com/feature-selection-using-random-forest-26d7b747597f
在第7部分中,用于绘制重要性分布图,提供了以下代码:
pd.series(sel.estimator_,feature_importances_,.ravel()).hist()
我认为应该没有语法错误:
pd.series(sel.estimator_,feature_importances_.ravel()).hist()
我收到此错误:
AttributeError:模块“ pandas”没有属性“ series”
答案 0 :(得分:1)
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()