Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get both score and accuracy after training

model.fit(X_train, y_train, batch_size = batch_size,
     nb_epoch = 4, validation_data = (X_test, y_test),
     show_accuracy = True)    
score = model.evaluate(X_test, y_test, 
     batch_size = batch_size, show_accuracy = True, verbose=0)

gives scalar output and hence the following code doesn't work.

print("Test score", score[0])
print("Test accuracy:", score[1])

The output that I get is: Train on 20000 samples, validate on 5000 samples

Epoch 1/4

20000/20000 [==============================] - 352s - loss: 0.4515 - val_loss: 0.4232

Epoch 2/4

20000/20000 [==============================] - 381s - loss: 0.2592 - val_loss: 0.3723

 Epoch 3/4

 20000/20000 [==============================] - 374s - loss: 0.1513 - val_loss: 0.4329

 Epoch 4/4

 20000/20000 [==============================] - 380s - loss: 0.0838 - val_loss: 0.5044

Keras version 1.0

How can I get the accuracy as well? Please help

like image 352
joydeep bhattacharjee Avatar asked May 03 '16 06:05

joydeep bhattacharjee


1 Answers

If you use Sequential model you can try (CODE UPDATED):

nb_epochs = 4
history = model.fit(X_train, y_train, batch_size = batch_size,
 nb_epoch = nb_epochs, validation_data = (X_test, y_test),
 show_accuracy = True)

print("Test score", history.history["val_loss"][nb_epochs - 1])
print("Test acc", history.history["val_acc"][nb_epochs - 1])
like image 98
Marcin Możejko Avatar answered Sep 25 '22 01:09

Marcin Możejko