Making Predictions
Making predictions on the trained model.
We'll cover the following...
The predict
function
Make predictions on the trained model.
Press + to interact
import numpy as npimport matplotlib.pyplot as pltA = x[0] # pixel values for letter AB = x[1] # pixel values for letter BC = x[2] # pixel values for letter Cdef 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 arrayprint("Highest value of index:", prediction[1][0])# plot the predicted labelplt.xlabel("Predicted label")plt.imshow(x[prediction[1][0]].reshape(5, 6))plt.show()plt.savefig('output/predicted.png')letter = A# printing the target labelplt.imshow(letter.reshape(5, 6))plt.xlabel("Target label")plt.show()plt.savefig('output/target.png')predict(letter, x)
Explanation
...
Access this course and 1400+ top-rated courses and projects.