Skip to content

Instantly share code, notes, and snippets.

@Tumurtogtokh
Created March 19, 2019 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tumurtogtokh/60052be0f8fcd3828286c301057fcbf9 to your computer and use it in GitHub Desktop.
Save Tumurtogtokh/60052be0f8fcd3828286c301057fcbf9 to your computer and use it in GitHub Desktop.
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