Exemple #1
0
validation_images = scaler.transform(validation_images)

# Set target values in our labels matrix to 0.15 and 0.85
for i in range(len(train_labels[:, 0])):
    for j in range(len(train_labels[0, :])):
        if train_labels[i, j] < 0.5:
            train_labels[i, j] = 0.1
        else:
            train_labels[i, j] = 0.9

# CREATE NeuralNet Object
NN = NeuralNet(train_images, train_labels)

# TRAIN NeuralNet Object
for i in range(1):
    x_plot, y_plot = NN.trainPlot(v_learning_rate=0.01, w_learning_rate=0.001)
    # Plot of cost function vs number of iterations.
    plt.plot(x_plot, y_plot, 'r-')
    plt.xlabel('Number of Iterations')
    plt.ylabel('J(y, z; x, V, W)')
    plt.title('Cost Function vs. Number of Iterations')
    plt.savefig('images/Cost_Function.png', bbox_inches='tight')

# TRAINING ACCURACY
y_hat = NN.classifyAll(train_images)
test_correct = 0
test_size = len(NN.images)
for i in range(test_size):
    if (y_hat[i] == np.argmax(NN.labels[i]) + 1):
        test_correct += 1
    else: