【问题标题】:How to use a 1D-CNN model in Lime?如何在 Lime 中使用 1D-CNN 模型?
【发布时间】:2020-01-30 22:57:47
【问题描述】:

我有一个数字健康记录数据集。我在分类步骤中使用了 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)

有解决办法吗?

【问题讨论】:

    标签: python keras lime


    【解决方案1】:

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

    【讨论】:

    • 它没有工作lime.lime_tabular.RecurrentTabularExplainer(train, feature_names=None) Traceback(最近一次调用最后):文件“”,第1行,在文件“/ lib/python3.6/site-packages/lime/lime_tabular.py",第 624 行,在 init for n in feature_names for i in range(n_timesteps)] TypeError: 'NoneType' object is not iterable
    • TypeError: 'NoneType' object is not iterable 似乎是 python 错误。请检查是什么原因造成的
    • 我无法找出问题
    • TypeError: 'NoneType' object is not iterable - 表示导致此错误的对象具有值 'none' ,这意味着该对象不包含任何值。检查代码中是哪个对象导致它。
    • 这就是为什么我给出了一个可复制的例子,因为我仍然有同样的错误。 lime.lime_tabular.RecurrentTabularExplainer(train, training_labels=y_train, feature_names=None) File "lime/lime_tabular.py", line 624, in init for n in feature_names for i in range(n_timesteps)] TypeError : 'NoneType' 对象不可迭代
    猜你喜欢
    • 2020-08-24
    • 1970-01-01
    • 1970-01-01
    • 2019-01-21
    • 2021-03-20
    • 2020-05-31
    • 1970-01-01
    • 1970-01-01
    • 2018-02-02
    相关资源
    最近更新 更多