-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblemF.py
More file actions
47 lines (35 loc) · 1.45 KB
/
Copy pathProblemF.py
File metadata and controls
47 lines (35 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import neuralnet
import numpy as np
import pickle
import matplotlib as mpl
mpl.use('TkAgg')
import matplotlib.pyplot as plt
def main():
train_data_fname = 'MNIST_train.pkl'
valid_data_fname = 'MNIST_valid.pkl'
test_data_fname = 'MNIST_test.pkl'
X_train, y_train = neuralnet.load_data(train_data_fname)
X_valid, y_valid = neuralnet.load_data(valid_data_fname)
X_test, y_test = neuralnet.load_data(test_data_fname)
#found this as the optimal number of epochs from Part C
neuralnet.config['epochs'] = 26
testshapes = [[784, 25, 10], [784, 100, 10], [784, 47, 47, 10]]
for shape in testshapes:
neuralnet.config['layer_specs'] = shape
network = neuralnet.Neuralnetwork(neuralnet.config)
training_errors, validation_errors, best_model, numEpochs = neuralnet.trainer(network, X_train, y_train, X_valid, y_valid, network.config)
network.layers = best_model
accuracy = neuralnet.test(network, X_test, y_test, network.config)
print("Shape: ", shape)
print("Accuracy", accuracy)
plt.plot(range(len(training_errors)), training_errors,"ro", color = "blue", label='Training Set Accuracy')
plt.plot(range(len(validation_errors)), validation_errors,"ro", color = "red", label='Validation Set Accuracy')
plt.legend(loc='upper left')
plt.xlabel("Epochs")
plt.ylabel("Percentage Correct")
plt.title("Training with " + str(shape) + " Shape")
name = "partF_" + str(shape) + ".png"
plt.savefig(name)
plt.close()
if __name__ == '__main__':
main()