第4章
4.1 利用神经网络完成商区分类任务
4.1.1 认识数据集
x_train, y_train, l_train = load_dataset("data/train.npz")
fig() + scatter(x_train, y_train, c=l_train)
4.1.2 搭建人工神经网络
model = DeepLearning([2,4,4,1])
fig() + structure(model)
4.1.3 神经网络训练
f_train = merge_features([x_train, y_train])
model.demo_train('business')
model.show_learning_curve()
4.1.4 神经网络测试
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 参数调整与重新训练
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 基于身高预测体重
4.2.1 写入实验数据
height, weight = load('hw.train')
height, weight = load('hw.train')
4.2.2 构建神经网络
net = MLP([1, 4, 4, 1])
fig() + structure(net)
4.2.3 神经网络训练
net.train(height, weight)
4.2.4 神经网络测试
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)