对于分类模型,“eli5.show_weights”究竟显示了什么?

2024-05-29 11:58:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用eli5来应用特征重要性的排列过程。在documentation中,有一些解释和一个小例子,但不清楚

我使用sklearn SVC模型来解决分类问题

我的问题是:这些权重是特定功能被洗牌时准确性的变化(减少/增加),还是这些功能的SVC权重

this medium article中,作者指出,这些值表明,通过重新调整该特性,降低了模型性能<但不确定是否确实如此

小例子:

from sklearn import datasets
import eli5
from eli5.sklearn import PermutationImportance
from sklearn.svm import SVC, SVR

# import some data to play with
iris = datasets.load_iris()
X = iris.data[:, :2]
y = iris.target

clf = SVC(kernel='linear')
perms = PermutationImportance(clf, n_iter=1000, cv=10, scoring='accuracy').fit(X, y)

print(perms.feature_importances_)
print(perms.feature_importances_std_)

[0.38117333 0.16214   ]
[0.1349115  0.11182505]

eli5.show_weights(perms)

enter image description here


Tags: from模型import功能irisdatasklearn例子
2条回答

对原始问题的回答稍微简短一点,不管cv参数的设置如何,eli5都将计算您提供的评分器的平均减少量。因为您使用的是sklearn包装器,所以记分器将来自scikitlearn:在您的例子中accuracy。总的来说,如果不深入了解源代码,其中一些细节就很难弄清楚,可能值得尝试提交一个pull请求,以尽可能使文档更加详细

我做了一些深入的研究。 在阅读了源代码之后,我认为这里使用的是cv,而不是prefitNone。我的应用程序使用K-Folds方案。我还使用了SVC模型,因此,score是这种情况下的准确度

通过查看PermutationImportance对象的fit方法,计算_cv_scores_importanceshttps://github.com/TeamHG-Memex/eli5/blob/master/eli5/sklearn/permutation_importance.py#L202)。使用指定的交叉验证方案,并使用测试数据返回base_scores, feature_importances(函数:_get_score_importancesinside _cv_scores_importances

通过查看get_score_importances函数(https://github.com/TeamHG-Memex/eli5/blob/master/eli5/permutation_importance.py#L55),我们可以看到base_score是非洗牌数据上的分数,feature_importances(在这里不同地称为:scores_decreases)被定义为非洗牌分数-洗牌分数(参见https://github.com/TeamHG-Memex/eli5/blob/master/eli5/permutation_importance.py#L93

最后,错误(feature_importances_std_)是上述feature_importanceshttps://github.com/TeamHG-Memex/eli5/blob/master/eli5/sklearn/permutation_importance.py#L209)的标准差,feature_importances_是上述feature_importances(非混洗分数减去(-)混洗分数)的平均值

相关问题 更多 >

    热门问题