Created
March 19, 2019 00:39
-
-
Save Tumurtogtokh/60052be0f8fcd3828286c301057fcbf9 to your computer and use it in GitHub Desktop.
PythonNN_demo005
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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