【发布时间】:2016-10-03 09:49:15
【问题描述】:
我想使用 Scikit learn 找出我的数据框中每个特征的重要性。
我试图在 Scikit learn 中使用它,而不是通过 WEKA 软件使用 Info Gain,后者提供分数和旁边的功能名称。
我实现了下一个方法,但是我不知道如何替换分数中的排名数字。
例如:
我不想看到:
- 功能 6
- 功能 4
...
不过,我更喜欢:
0.4 特征 6
0.233 特征 4
...
这是我的方法:
def _rank_features(self, dataframe, targeted_class):
from sklearn.feature_selection import RFE
from sklearn.linear_model import LinearRegression
feature_names = list(dataframe.columns.values)
# use linear regression as the model
lr = LinearRegression()
# rank all features, i.e continue the elimination until the last one
rfe = RFE(lr, n_features_to_select=1)
rfe.fit(dataframe, targeted_class)
print "Features sorted by their rank:"
print sorted(zip(map(lambda x: round(x, 4), rfe.ranking_), feature_names))
有人知道如何将排名转换为分数吗?
【问题讨论】:
-
代码的输出是什么?它不起作用?
-
输出如下所示:按排名排序的美食:[(1.0, 'feature 6'), (2.0, 'feature 4'), (3.0, 'feature 3'), .. . ]
-
sklearn 中的 RFE 只是消除了给定阈值的最差特征(如果您查看源代码),它不计算特点
标签: pandas scikit-learn rfe