from dlgo.nn import load_mnist from dlgo.nn import network from dlgo.nn.layers import DenseLayer, ActivationLayer # first load training and test data training_data, test_data = load_mnist.load_data() # Next initialize a sequential neural network net = network.SequentialNetwork() # you can then add dense and activation layers one by one net.add(DenseLayer(784, 392)) net.add(ActivationLayer(392)) net.add(DenseLayer(392, 196)) net.add(ActivationLayer(196)) net.add(DenseLayer(196, 10)) net.add(ActivationLayer(10)) # the final layer has size 10, the number of classes to predict # You can now easily train the model by specifying train and test data, the number of epochs, the mini-batch size and the learning rate. net.train(training_data, epochs=10, mini_batch_size=10, learning_rate=3.0, test_data=test_data)
from dlgo.nn import load_mnist from dlgo.nn import network from dlgo.nn.layers import DenseLayer, ActivationLayer training_data, test_data = load_mnist.load_data( ) # First, load training and test data. net = network.SequentialNetwork( ) # Next, initialize a sequential neural network. net.add(DenseLayer( 784, 392)) # You can then add dense and activation layers one by one. net.add(ActivationLayer(392)) net.add(DenseLayer(392, 196)) net.add(ActivationLayer(196)) net.add(DenseLayer(196, 10)) net.add(ActivationLayer( 10)) # The final layer has size 10, the number of classes to predict. # You can now easily train the model by specifying train and test data, # the number of epochs, the mini-batch size and the learning rate. net.train(training_data, epochs=10, mini_batch_size=10, learning_rate=3.0, test_data=test_data)
return np.average(filtered_array, axis=0) def predict(x, W, b): return sigmoid_double(np.dot(W, x) + b) def evaluate(data, digit, threshold, W, b): correct_predictions = 0 for x in data: if (predict(x[0], W, b) > threshold) == (np.argmax(x[1]) == digit): correct_predictions += 1 return correct_predictions / float(len(data)) train, test = load_data() W_8 = np.transpose(average_digit(train, 8)) b_8 = -45 # print(predict(train[2][0], W_8, b_8)) # print(predict(train[17][0], W_8, b_8)) print(evaluate(data=train, digit=8, threshold=0.5, W=W_8, b=b_8)) print(evaluate(data=test, digit=8, threshold=0.5, W=W_8, b=b_8)) print( evaluate(data=[x for x in test if np.argmax(x[1]) == 8], digit=8, threshold=0.5, W=W_8, b=b_8))