问题
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)
回答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.
An example of code:
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]
This way wrong_predictions
contains rows, where your prediction as wrong.
来源:https://stackoverflow.com/questions/55074681/how-to-find-the-wrong-predictions-in-keras