def train(train_x, train_y, layers): nn = NeuralNetwork(layer_dims=layers, keep_prop=0.8, weight_factor=len(layers) > 2 and 'deep' or 0.01) def print_cost(iteration_num, cost): if iteration_num % 100 == 0: print("Cost after iteration %d: %f" % (iteration_num, cost)) nn.train(train_x, train_y, num_iterations=2500, callback=print_cost) return nn
def train(train_x, train_y, test_x, test_y): def print_cost(iteration_num, cost): if iteration_num % 100 == 0: print("Cost after iteration %d: %f" % (iteration_num, cost)) nn = NeuralNetwork(layer_dims=[20, 3, 1], num_iterations=3000, weight_factors='deep', callback=print_cost) nn.train(train_x, train_y) p = nn.predict(train_x) print('Accuracy: %f' % np.mean(p == train_y)) p = nn.predict(test_x) print('Accuracy: %f' % np.mean(p == test_y))