我使用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)
我做了一些深入的研究。在看完源代码之后,我相信对于使用cv
而不是prefit
或None
的情况。我为我的应用程序使用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_
的平均值(非随机分数减去(-)随机分数)。