1

我有一个数字健康记录数据集。我在分类步骤中使用了 1D CNN keras 模型。

我在 Python 中给出了一个可复制的例子:

import tensorflow as tf
import keras
from keras.models import Sequential
from keras.layers import Conv1D, Activation, Flatten, Dense
import numpy as np

a = np.array([[0,1,2,9,3], [0,5,1,33,6], [1, 12,1,8,9]])
train = np.reshape(a[:,1:],(a[:,1:].shape[0], a[:,1:].shape[1],1))
y_train = keras.utils.to_categorical(a[:,:1])

model = Sequential()
model.add(Conv1D(filters=2, kernel_size=2, strides=1, activation='relu', padding="same", input_shape=(train.shape[1], 1), kernel_initializer='he_normal'))

model.add(Flatten())
model.add(Dense(2, activation='sigmoid'))

model.compile(loss=keras.losses.binary_crossentropy,
                 optimizer=keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, amsgrad=False),
                 metrics=['accuracy'])

model.fit(train, y_train, epochs=3, verbose=1)

将石灰应用于 1D CNN 模型时出现此错误

IndexError: boolean index did not match indexed array along dimension 1; dimension is 4 but corresponding boolean dimension is 1
import lime
import lime.lime_tabular

explainer = lime.lime_tabular.LimeTabularExplainer(train)

有解决办法吗?

4

1 回答 1

0

您应该尝试使用 Lime_tabular.RecurrentTabularExplainer而不是 LimeTabularExplainer。它是 keras 风格的递归神经网络的解释器。查看 LIME 文档中的示例以获得更好的理解。祝你好运:)

于 2020-02-05T23:31:49.327 回答