如何在Keras中找到错误的预测? [英] How to find the wrong predictions in Keras?

查看:206
本文介绍了如何在Keras中找到错误的预测?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了一个Keras模型,用于从文本输入的原始输入中提取信息.我的准确度是0.9869.我怎么知道哪个训练数据使准确性降低?我已经在下面粘贴了我正在使用的代码.

I have built a Keras model for extracting information from a raw input of text input. I am getting an accuracy of 0.9869. How can I know which of the training data is making the accuracy go low? I have pasted the code I am using below.

import numpy as np  
from keras.models import Model, load_model
from keras.layers import Input, Dense, LSTM, Activation, Bidirectional, Dot, Flatten
from keras.callbacks import ModelCheckpoint

x_nyha = np.load("data/x_nyha.npy")
y_nyha = np.load("data/y/y_nyha.npy")
print(x_nyha.shape)
print(y_nyha.shape)


input_shape = x_nyha.shape[1:3]

X = Input(shape=input_shape)
A = Bidirectional(LSTM(512, return_sequences=True), merge_mode='concat')(X)
D = Dense(900, activation='relu')(A)
E = Dense(1, activation='sigmoid')(D)
Y = Flatten()(E)
model = Model(X, Y)
model.summary()

model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])


batch_size = 128
num_epochs = 50


model.fit(x_nyha, y_nyha, batch_size=batch_size, epochs=num_epochs, verbose=1)

推荐答案

我认为最简单的方法是:根据训练数据训练模型,对训练数据进行预测,并查看预测错误的训练样本

I think that the easiest way will be the following: train model on training data, make predictions on training data and have a look at training samples where predictions are wrong.

代码示例:

model.fit(x_nyha, y_nyha, batch_size=batch_size, epochs=num_epochs, verbose=1)
prediction = np.round(model.predict(x_nyha))
wrong_predictions = x_nyha[prediction != y_nyha]

这种方式wrong_predictions包含行,您的预测错误.

This way wrong_predictions contains rows, where your prediction as wrong.

这篇关于如何在Keras中找到错误的预测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆