【问题标题】:What exactly does `eli5.show_weights` display for a classification model?`eli5.show_weights` 究竟为分类模型显示了什么?
【发布时间】:2020-06-12 21:32:36
【问题描述】:

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

【问题讨论】:

    标签: python machine-learning scikit-learn classification eli5


    【解决方案1】:

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

    通过查看PermutationImportance 对象的fit 方法,可以计算出_cv_scores_importances (https://github.com/TeamHG-Memex/eli5/blob/master/eli5/sklearn/permutation_importance.py#L202)。使用指定的交叉验证方案,并使用测试数据返回base_scores, feature_importances(函数:_get_score_importances inside _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)被定义为非混洗数据score - 打乱的分数(见https://github.com/TeamHG-Memex/eli5/blob/master/eli5/permutation_importance.py#L93

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

    【讨论】:

      【解决方案2】:

      无论cv 参数的设置如何,eli5 都会计算您提供的得分者的平均减少量。因为您使用的是 sklearn 包装器,所以记分器将来自 scikit-learn:在您的情况下为 accuracy。总的来说,作为包的一个词,如果不深入研究源代码,其中一些细节特别难以弄清楚,可能值得尝试提交拉取请求以使文档尽可能详细。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-01-24
        • 1970-01-01
        • 2012-07-23
        • 2016-09-10
        • 2023-03-15
        • 2012-10-17
        • 2021-06-04
        • 1970-01-01
        相关资源
        最近更新 更多