LIME 可解释性与 Python 上的 4D 训练数据

问题描述 投票:0回答:0

我正在处理一个需要输入 4D 数组的深度学习模型,我想使用 LIME 来对我的结果进行一些解释

我正在使用 lime_tabular.RecurrentTabularExplainer 但它需要一个 3D numpy 数组作为训练数据,但我的训练数据是一个 4D 数组。

我试过这个代码

from lime.lime_tabular import RecurrentTabularExplainer
explainer = RecurrentTabularExplainer(
    X_train, 
    feature_names=reference_columns, 
    class_names=['No_error', 'Error'], 
    categorical_features=[0, 1]
    #positive_class=0,
    #method='exhaustive'
)

exp = explainer.explain_instance(
    data_row = X_train[0,:,:,:],
    classifier_fn = model_1.predict)

我收到错误:“要解压的值太多(预期为 3)”,因为我正在传递 4D 数组。


我也尝试过这种方法。由于我的数组形状为 (5240, 57, 37, 1),因此在将它传递给 RecurrentTabularExplainer 时,我将其重塑为 (5240, 57, 37)

from lime import lime_tabular

explainer = lime_tabular.RecurrentTabularExplainer(
    X_train.reshape(X_train.shape[0], X_train.shape[1], X_train.shape[2]),
    training_labels = y_train,
    feature_names = reference_columns,
    discretize_continuous = True,
    class_names = ['0','1'],
    discretizer = 'decile')

exp = explainer.explain_instance(
    data_row = X_train[0,:,:,:],
    classifier_fn = model_1.predict)

exp.show_in_notebook()

但随后我在 explainer_instance 中收到此错误:“ValueError:顺序层的输入 0 与层不兼容:预期 ndim=4,发现 ndim=3。收到完整形状:[None, 57, 37]”


我该如何解决这个问题?

python deep-learning lime
© www.soinside.com 2019 - 2024. All rights reserved.