特征重要性,需要将最重要的变量捕获到数据框中,类似于 Boruta (R) 但在 Python 中

问题描述 投票:0回答:0

问题

在 RandomForestRegressor 上使用特征重要性,需要将最重要的变量捕获到数据框中。

我尝试了“sorted_indices = np.argsort(importance)[::-1][:n]”,其中 n=50,但这只提供了特征的索引号,而不是特征名称标签。

有没有一种方法可以使用“importance = rfe.feature_importances_.argsort()”仅将最重要的特征系数捕获到数据框中,以保存到特征列表中,以便稍后在建模过程中使用。这类似于我正在寻找的 R Boruta 方法,如果有人知道如何在 Python 中将相似的特征重要性实现到数据框架中,而不仅仅是可视化。我已经有了用于特征可视化的“yellowbrick”包。现在需要保存功能。

代码

rfe = RandomForestRegressor(n_estimators = 500)
rfe.fit(X_train, Y_train)
importance = rfe.feature_importances_.argsort()

from yellowbrick.model_selection import FeatureImportances

viz = FeatureImportances(rfe, stack=True, relative=False, topn=50)
labels = list(map(lambda s: s.title(), train_data))
viz = FeatureImportances(Lasso(), labels=labels, relative=False, topn=50)
viz.fit(X, y)
viz.show()

提案

类似于“for j in range(”特征重要性): dataframe = "特征标签,特征重要性"

比如使用一个重要的分数,并为有限数量的特征按降序对值进行排序,比如,n=50

python linear-regression feature-selection
© www.soinside.com 2019 - 2024. All rights reserved.