Chapter 4
4.1 Use neural network to complete the business district classification task
4.1.1 Understanding Datasets
x_train, y_train, l_train = load_dataset("data/train.npz")
fig() + scatter(x_train, y_train, c=l_train)
4.1.2 Build artificial neural network
model = DeepLearning([2,4,4,1])
fig() + structure(model)
4.1.3 Neural Network Training
f_train = merge_features([x_train, y_train])
model.demo_train('business')
model.show_learning_curve()
4.1.4 Neural Network Test
x_test, y_test, l_test = load_dataset("data/test.npz")
f_test = merge_features([x_test, y_test])
pred = model.predict(f_test)
print(accuracy(pred > 0.5, l_test))
4.1.5 Parameter adjustment and retraining
model.reset_weights()
model.loss = 'mse'
model.demo_train('business_mse')
model.show_learning_curve()
pred = model.predict(f_test)
print(accuracy(pred > 0.5, l_test))
4.2 Predicting weight based on height
4.2.1 Write experimental data
height, weight = load('hw.train')
height, weight = load('hw.train')
4.2.2 Building a neural network
net = MLP([1, 4, 4, 1])
fig() + structure(net)
4.2.3 Neural Network Training
net.train(height, weight)
4.2.4 Neural Network Test
t_height, t_weight = load('hw.test')
pred = net.predict(data=t_height)
fig() + scatter(t_height, pred) + scatter(t_height, t_weight)
error = net.compute_error(pred, t_weight)
print("Test error = %f" % error)