python - scikit 特征重要性选择经验

标签 python classification scikit-learn

Scikit-learn 有一种使用极端随机树对特征进行排序(分类)的机制。

forest = ExtraTreesClassifier(n_estimators=250,
                          compute_importances=True,
                          random_state=0)

我有一个问题,此方法是否正在进行“单变量”或“多变量”特征排名。单变量情况是各个特征之间进行比较。我希望能在这里做出一些澄清。我应该尝试调整其他任何参数吗?任何有关此排名方法的经验和陷阱也值得赞赏。 该排名的输出识别特征编号(5,20,7。我想检查特征编号是否确实对应于特征矩阵中的行。也就是说,特征编号5对应于特征矩阵中的第六行(从0开始)。

最佳答案

我不是专家,但这不是单变量。事实上,总特征重要性是根据每棵树的特征重要性计算出来的(取我认为的平均值)。

对于每棵树,计算重要性 from the impurity of the split .

我使用了这种方法,它似乎给出了很好的结果,从我的角度来看比单变量方法更好。但除了数据集的知识之外,我不知道任何测试结果的技术。

要正确订购该功能,您应该遵循 this example并对其进行修改以使用 pandas.DataFrame 及其正确的列名称:

import numpy as np

from sklearn.ensemble import ExtraTreesClassifier

X = pandas.DataFrame(...)
Y = pandas.Series(...)

# Build a forest and compute the feature importances
forest = ExtraTreesClassifier(n_estimators=250,
                              random_state=0)

forest.fit(X, y)

feature_importance = forest.feature_importances_
feature_importance = 100.0 * (feature_importance / feature_importance.max())
sorted_idx = np.argsort(feature_importance)[::-1]
print "Feature importance:"
i=1
for f,w in zip(X.columns[sorted_idx], feature_importance[sorted_idx]):
    print "%d) %s : %d" % (i, f, w)
    i+=1
pos = np.arange(sorted_idx.shape[0]) + .5
plt.subplot(1, 2, 2)
nb_to_display = 30
plt.barh(pos[:nb_to_display], feature_importance[sorted_idx][:nb_to_display], align='center')
plt.yticks(pos[:nb_to_display], X.columns[sorted_idx][:nb_to_display])
plt.xlabel('Relative Importance')
plt.title('Variable Importance')
plt.show()

关于python - scikit 特征重要性选择经验,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12970255/

相关文章:

python - 有没有既可以在单词级别也可以在句子级别工作的分类器?

r - 设置随机种子不影响分类方法C5.0和ctree

python - 使用 scikit-learn 线性 SVM 提取决策边界

python - 比较python中的两个字符串?

python - 将 mkv 文件转换为 mp4 给我 `filenotfounderror`

Python Git Bash CMD 脚本

python - 在多标签分类中使用样本权重

python - 将分类移至生产环境

python - 拟合函数返回 TypeError : float() argument must be string or a number in ScikitLearn

python - LSTM 在第二次测试数据上表现不佳