loglevel=args.verbosity) loss_function = loss.SquaredErrorFunction() gdo = optimizer.GradientDescentOptimizer(learning_rate=params.learning_rate) nn_model = model.ModelWrapper(network=fc_net, optimizer=gdo, loss_function=loss_function, x=X, y_target=labels_onehot, params=params) # Run training loss = nn_model.train() nn_model.network.saveModel('./models', 'trained.pkl') score_train = sup.computeScore(fc_net, X, labels_onehot) print( 'The classification score on the training data is {}.'.format(score_train)) # Plotting training specs if plotting_active: pl.figure('Loss evolution') ax = pl.gca() ax.plot(loss[:, 0], loss[:, 1], c='b', label='training error') ax.set_ylim([-0.2, 1.2]) ax.set_xlabel('Training step') ax.set_ylabel('Training error') # Visualization of classification results mesh_step_size = 0.02 x1_min, x1_max = X[:, 0].min() - .5, X[:, 0].max() + .5
action='store_true', default=False) return parser.parse_args() args = parse_args() test_data = pkl.load(open('./data/data_test.pkl', 'rb')) fc_net = network.FCNetwork() fc_net.loadModel('./models/', 'trained.pkl') X_test = test_data[0] labels_test = test_data[1] # Compute scores on training and testing data score_test = sup.computeScore(fc_net, X_test, labels_test) print('The classification score on the test data is {}'.format(score_test)) # Visualization of classification results if args.plot: mesh_step_size = 0.05 x1_min, x1_max = X_test[:, 0].min() - .5, X_test[:, 0].max() + .5 x2_min, x2_max = X_test[:, 1].min() - .5, X_test[:, 1].max() + .5 xx1, xx2 = np.meshgrid(np.arange(x1_min, x1_max, mesh_step_size), np.arange(x2_min, x2_max, mesh_step_size)) predicted_label = np.zeros(xx1.shape) for ii in range(xx1.shape[0]): for jj in range(xx1.shape[1]): x_query = np.array([[xx1[ii, jj], xx2[ii, jj]]]) y_net = fc_net.output(x_query)