python - 对于分类模型, `eli5.show_weights` 究竟显示了什么?

标签 python machine-learning scikit-learn classification eli5

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

最佳答案

我做了一些深入的研究。 在查看源代码后,我相信使用 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(函数:_cv_scores_importances 内的_get_score_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 ( https://github.com/TeamHG-Memex/eli5/blob/master/eli5/sklearn/permutation_importance.py#L209 ) 的标准差,feature_importances_ 是上述 feature_importances(非打乱分数减去 (-) 打乱分数)。

关于python - 对于分类模型, `eli5.show_weights` 究竟显示了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60457480/

相关文章:

python - 在 anaconda 上更新 python

machine-learning - 用于 Web 应用程序的 SVM

machine-learning - 核回归与线性核回归相同吗?

python - Scikit F 分数度量误差

python - sknn - 第二次拟合时输入尺寸不匹配

python - 如何在 Python 3 中覆盖 file.write()?

python - 将一个数组的每个元素除以另一个数组的每个元素

Python:在主线程中执行回调方法

python - scikit-learn 中的多输出高斯过程回归

python - 恢复 tensorflow 模型时出现NotFoundError