对于分类模型,eli5.show_weights到底显示什么?

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

我使用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

python machine-learning scikit-learn classification eli5
1个回答
0
投票

我做了一些深入的研究。在看完源代码之后,我相信对于使用cv而不是prefitNone的情况。我为我的应用程序使用K折方案。我也使用了SVC模型,因此score在这种情况下就是准确性。

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

[通过查看_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_importances)的SD,https://github.com/TeamHG-Memex/eli5/blob/master/eli5/sklearn/permutation_importance.py#L209是上述feature_importances_的平均值(非随机分数减去(-)随机分数)。

© www.soinside.com 2019 - 2024. All rights reserved.