Making Predictions

Making predictions on the trained model.

We'll cover the following...

The predict function

Make predictions on the trained model.

Python 3.5
import numpy as np
import matplotlib.pyplot as plt
A = x[0] # pixel values for letter A
B = x[1] # pixel values for letter B
C = x[2] # pixel values for letter C
def predict(letter, x):
"""Computes predictions on the trained weights and bias"""
out_h1, out_h2, out_y = forward_propagation(letter, w1, w2, w3, b1, b2, b3)
print("softmax output:", out_y)
prediction = np.where(out_y == np.amax(out_y)) # returns the maximum value of array
print("Highest value of index:", prediction[1][0])
# plot the predicted label
plt.xlabel("Predicted label")
plt.imshow(x[prediction[1][0]].reshape(5, 6))
plt.show()
plt.savefig('output/predicted.png')
letter = A
# printing the target label
plt.imshow(letter.reshape(5, 6))
plt.xlabel("Target label")
plt.show()
plt.savefig('output/target.png')
predict(letter, x)

Explanation

Recall that x[0] has the letter A pixel values, x[1] has letter B pixel values, x[2] has letter C pixel values. ...