def cee_accuracy(): from hw6code import ERROR_CEE, Neural_Network import random np.random.seed(12) random.seed(13) data = load_trains() trains = data[:-10000] tests = data[-5000:] nnetc = Neural_Network(error_function=ERROR_CEE) nnetc.progressive_init(trains) def get_accuracy(): total = 0 correct = 0 for test in tests: hw = nnetc.predict(test) hj = vector_to_label(hw) if hj == test.yl: correct += 1 total += 1 return correct / total for reps_goal in xrange(0, 300000, 1000): nnetc.reps = reps_goal nnetc.prog_train() accuracyc = get_accuracy() print reps_goal, accuracyc ceelist.append(accuracyc)
def training_accuracy(): from hw6code import Neural_Network, ERROR_CEE, ERROR_MSE import random np.random.seed(12) random.seed(13) data = load_trains() nnet = Neural_Network(error_function=ERROR_CEE) nnet.train(data) total = 0 correct = 0 for test in data: hw = nnet.predict(test) hj = vector_to_label(hw) if hj == test.yl: correct += 1 total += 1 print correct / total
def kaggle(): from hw6code import Neural_Network import random import csv np.random.seed(12) random.seed(13) trains = load_trains() tests = load_tests() nnet = Neural_Network() nnet.train(trains) count = 1 print("WRITING") with open('hw6submit.csv', 'w') as f: digitwriter = csv.writer(f, delimiter=',') digitwriter.writerow(['Id', 'Category']) for test in tests: hv = nnet.predict(test) hl = vector_to_label(hv) digitwriter.writerow([count, hl]) count += 1