`eli5.show_weights` 在分类模型中显示什么内容?

我使用了 eli5 来执行特征重要性的置换过程。在文档中,有一些解释和一个小例子,但不够清晰。

我正在使用 sklearn SVC 模型进行分类问题。

我的问题是: 这些权重是指当特定特征被打乱时准确率的变化(减少/增加)还是这些特征的 SVC 权重?

这篇 Medium 文章中,作者指出这些值显示了“该特征重新洗牌后模型性能的降低”。但我不确定是否确实如此。

小例子:

from sklearn import datasetsimport eli5from eli5.sklearn import PermutationImportancefrom sklearn.svm import SVC, SVR# import some data to play withiris = datasets.load_iris()X = iris.data[:, :2]y = iris.targetclf = 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_importanceshttps://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 的标准差(https://github.com/TeamHG-Memex/eli5/blob/master/eli5/sklearn/permutation_importance.py#L209),而 feature_importances_ 是上述 feature_importances 的平均值(未打乱得分减去打乱得分)。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注