2.3 Train the model

Let's trains the model for a given number of epochs.

In [9]:
results = model.fit(
 X_train, y_train.T,
 epochs= training_epochs,
 validation_data = (X_test, y_test.T),
 verbose = 0
)

2.4 Test the model

The model can generate output predictions for the input samples.

In [10]:
prediction_values = model.predict_classes(X_test)
print("Prediction values shape:", prediction_values.shape)
Prediction values shape: (660, 1)

2.5 Accuracy

In [11]:
print(np.mean(results.history["val_accuracy"]))
0.7972828

2.6 Evaluate the model to see the accuracy

Now we can check the accuracy of our model

In [12]:
print("Evaluating on training set...")
(loss, accuracy) = model.evaluate(X_train, y_train.T, verbose=0)
print("loss={:.4f}, accuracy: {:.4f}%".format(loss,accuracy * 100))

print("Evaluating on testing set...")
(loss, accuracy) = model.evaluate(X_test, y_test.T, verbose=0)
print("loss={:.4f}, accuracy: {:.4f}%".format(loss,accuracy * 100))
Evaluating on training set...
loss=0.0031, accuracy: 99.9254%
Evaluating on testing set...
loss=0.0025, accuracy: 100.0000%

2.7 Summarize history for accuracy

In [13]:
# summarize history for accuracy
plt.plot(results.history['accuracy'])
plt.plot(results.history['val_accuracy'])
plt.title('model accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='down right')
Out[13]:
<matplotlib.legend.Legend at 0x1858f005f98>

2.8 Summarize history for loss

In [14]:
# summarize history for loss
plt.plot(results.history['loss'])
plt.plot(results.history['val_loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper right')

max_loss = np.max(results.history['loss'])
min_loss = np.min(results.history['loss'])
print("Maximum Loss : {:.4f}".format(max_loss))
print("")
print("Minimum Loss : {:.4f}".format(min_loss))
print("")
print("Loss difference : {:.4f}".format((max_loss - min_loss)))
Maximum Loss : 0.8771

Minimum Loss : 0.0033

Loss difference : 0.8738