【发布时间】:2020-06-14 19:31:11
【问题描述】:
PermutationImportance 对象有一些不错的属性,例如 feature_importances_ 和 feature_importances_std_。
为了以 HTML 样式可视化这个属性,我使用了eli5.show_weights 函数。但是,我注意到显示的标准偏差与feature_importances_std_ 中的值不一致。
更具体地说,我可以看到显示的 HTML 值等于 feature_importances_std_ * 2。为什么会这样?
代码:
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] # we only take the first two features.
y = iris.target
clf = SVC()
perms = PermutationImportance(clf, n_iter=1000, cv=10, random_state=0).fit(X, y)
print(perms.feature_importances_)
# this is the actual SD
print(perms.feature_importances_std_)
# These are the displayed values
print(perms.feature_importances_std_* 2)
[0.39527333 0.17178 ] # the actual mean
[0.13927548 0.11061278] # the actual SD
[0.27855095 0.22122556] # the displayed values by `show_weights()`
eli5.show_weights(perms)
我们可以看到显示的标准差增加了一倍,即2 * perms.feature_importances_std_。
这可能是一个错误吗?
【问题讨论】:
-
你试过用 explain_weights 代替 show_weights 吗?结果一样吗?
-
我试过了,是的。没有什么变化。见这里:pasteboard.co/IXF26AD.png
-
特征重要性也可以使用rfpimp。
-
有趣的是,他们也使用
eli5。在此处查看最后一个代码单元:github.com/parrt/random-forest-importances/blob/master/… -
这仅适用于随机森林模型吗? 有趣的事情,他们也使用
eli5。查看最后一个代码单元here
标签: python scikit-learn eli5