Keras - Exact Training, Verification and Test Accuracy

I want to build the output of this simple neural network:

model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) history = model.fit(x_test, y_test, nb_epoch=10, validation_split=0.2, shuffle=True) model.test_on_batch(x_test, y_test) model.metrics_names 

I built accuracy and loss of training and verification:

 print(history.history.keys()) # "Accuracy" plt.plot(history.history['acc']) plt.plot(history.history['val_acc']) plt.title('model accuracy') plt.ylabel('accuracy') plt.xlabel('epoch') plt.legend(['train', 'validation'], loc='upper left') plt.show() # "Loss" plt.plot(history.history['loss']) plt.plot(history.history['val_loss']) plt.title('model loss') plt.ylabel('loss') plt.xlabel('epoch') plt.legend(['train', 'validation'], loc='upper left') plt.show() 

Now I want to add and set the accuracy of the test model.test_on_batch(x_test, y_test) from model.test_on_batch(x_test, y_test) , but from model.metrics_names I get the same value "acc" that is used to build the accuracy of the training data plt.plot(history.history['acc']) . How can I adjust the accuracy of the test suite?

+15
keras
source share
3 answers

This is the same thing because you train on a test set, not on a train set. Do not do this, just train on a training set:

 history = model.fit(x_test, y_test, nb_epoch=10, validation_split=0.2, shuffle=True) 

Change to:

 history = model.fit(x_train, y_train, nb_epoch=10, validation_split=0.2, shuffle=True) 
+6
source share

Confirm the model on the test data as shown below, and then plot the accuracy and loss on the graph.

 model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) history = model.fit(X_train, y_train, nb_epoch=10, validation_data=(X_test, y_test), shuffle=True) 
0
source share
 import keras from matplotlib import pyplot as plt history = model1.fit(train_x, train_y,validation_split = 0.1, epochs=50, batch_size=4) plt.plot(history.history['acc']) plt.plot(history.history['val_acc']) plt.title('model accuracy') plt.ylabel('accuracy') plt.xlabel('epoch') plt.legend(['train', 'val'], loc='upper left') plt.show() 

Model Accuracy

 plt.plot(history.history['loss']) plt.plot(history.history['val_loss']) plt.title('model loss') plt.ylabel('loss') plt.xlabel('epoch') plt.legend(['train', 'val'], loc='upper left') plt.show() 

Model loss

0
source share

All Articles