Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PythonNN_demo005
import numpy as np
from neural_network import NeuralNetwork as NN
# Number of input, hidden, and output nodes
input_nodes = 784
hidden_nodes = 100
output_nodes = 10
# Learning rate
learning_rate = 0.1
# Initialise Neural network
N = NN(input_nodes, hidden_nodes, output_nodes, learning_rate)
# TRAINING
epochs = 2
for epoch in range(epochs):
for sample in training_data:
sample_values = sample.split(',')
# scale and shift input
inputs = (np.asfarray(sample_values[1:]) / 255.0 * 0.99) + 0.01
# create target values (0.01 -> 0.99)
targets = np.zeros(output_nodes) + 0.01
# assign desired target values
targets[int(sample_values[0])] = 0.99
N.train(inputs, targets)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.