Python 如何通过一个datashape(35087、15103)获得每个特性的贡献?
我最近发现了一个非常好的github存储库,名为用Python和JavaScript编写的。它可以用来解释任何机器学习模型的输出。你可以看到一个很好的视频,很好地解释了图书馆 在一个用python编写的分类问题中,我发现我在使用这个库时会遇到一些小问题 说明: 我使用了103个特性来建模-1、0和1所描述的三个标签。 我的所有功能都有很好的定义,并且都有一个相关的标题。我的问题是我没有在每个单元中通过103个特性。我在每个时间单位传递Python 如何通过一个datashape(35087、15103)获得每个特性的贡献?,python,keras,Python,Keras,我最近发现了一个非常好的github存储库,名为用Python和JavaScript编写的。它可以用来解释任何机器学习模型的输出。你可以看到一个很好的视频,很好地解释了图书馆 在一个用python编写的分类问题中,我发现我在使用这个库时会遇到一些小问题 说明: 我使用了103个特性来建模-1、0和1所描述的三个标签。 我的所有功能都有很好的定义,并且都有一个相关的标题。我的问题是我没有在每个单元中通过103个特性。我在每个时间单位传递103*15特征,即当前时间t\u 0的103特征和时间t\u
103*15
特征,即当前时间t\u 0
的103特征和时间t\u-1,…,t\u-14
的相同特征。我的火车数据集的形状是(35087,15,103)
,其中第一个参数表示35087秒
下面是我可以使用它的一个明显的方法:
import shap
# we use the first 100 training examples as our background dataset to integrate over
explainer = shap.DeepExplainer(model, x_train[:100])
# explain the first 10 predictions
# explaining each prediction requires 2 * background dataset size runs
shap_values = explainer.shap_values(x_test[:10])
# init the JS visualization code
shap.initjs()
# transform the indexes to words
import numpy as np
words = imdb.get_word_index()
num2word = {}
for w in words.keys():
num2word[words[w]] = w
x_test_words = np.stack([np.array(list(map(lambda x: num2word.get(x, "NONE"), x_test[i]))) for i in range(10)])
# plot the explanation of the first prediction
# Note the model is "multi-output" because it is rank-2 but only has one column
shap.force_plot(explainer.expected_value[0], shap_values[0][0], x_test_words[0])
我想得到的东西很简单
如何处理时间t_-1,…,t_-14的特性,以获得每个特性的贡献
更新
以下是我尝试的更新:
因此,最初,我有103
功能和3
标签<代码>X_列车。形状是(35087,15,103)
和X_测试。形状
是(11696,15,103)
这里的shap\u值
似乎是一个由三个shape(10、15、103)
数组组成的列表
从那里我得到了错误***索引器错误:索引40超出了大小为15的轴0的界限
有没有人能帮我把以上信息整理成摘要图?你用的是什么样的模型?是测试数据的混淆矩阵吗?这很有趣,但由于您使用的是测试数据,因此这可能是过度拟合训练数据的一个示例。当你重复训练和测试时,一般结果是否相同?你的数据在训练集中是否被分割成序列长度序列重叠?
explainer = shap.DeepExplainer(Model.model, X_train[:100])
shap_values = explainer.shap_values(X_test[:10])
X_test_flatten = X_test.flatten()
shap.summary_plot(shap_values, X_test_flatten, features_names=FEATURES)