我的简化模型如下所示:
model = Sequential()
model.add(LSTM(12, input_shape=(1000,12)))
model.add(Dense(9, activation='sigmoid'))
我的培训数据的形状如下:
(900,1000,12)
从输出层可以看出,我有9个输出,因此每个信号(长度为1000)将被分类为一个或多个输出(这是一个多标签分类)
我训练我的模特如下:
history = model.fit(X_train,y_train, batch_size=32, epochs=10,validation_data=(X_val,y_val),verbose=2)
到目前为止一切正常,但现在我想用石灰来解释分类
explainer = lime_tabular.RecurrentTabularExplainer(X_train, training_labels=y_train,feature_names=['1','2','3','4','5','6','7','8','9','10','11','12'],
discretize_continuous=True,
class_names=['a','b','c','d','e','f','g','h','i'],
discretizer='decile')
当我定义我的解释程序时,我没有得到任何错误,但是当我试图运行下面的代码时,它在给我一个错误之前运行了很长时间
exp=explainer.explain_instance(data_row=X[0].reshape(1,1000,12),classifier_fn= model)
exp.show_in_notebook()
NotImplementedError: LIME does not currently support classifier models without probability scores.
If this conflicts with your use case, please let us know: https://github.com/datascienceinc/lime/issues/16
有人能认识到这个错误或看出什么地方出了问题吗
您应该将分类器预测概率函数传递给
explainer.explain_instance
中的classifier_fn
,该函数接受一个numpy数组并输出预测概率:在您的例子中model.predict_proba
(如果它产生概率,那么model.predict
也可以工作)还请注意,在您的情况下,预测概率总和不等于1,因为您在最后一层中应用了
sigmoid
激活。考虑切换到{{CD6>}以产生概率为1下面是完整的示例:
拟合虚拟模型
初始化解释程序
举例说明:
相关问题 更多 >
编程相关推荐