我正在尝试训练一个深度神经网络,以确定如果 X 的前两列中存在 1 和 0,则输出为 1,否则为 0。但我只能在模型上获得 75% 的准确度!
将 numpy 导入为 np 导入 tflearn
X = [[0, 0, 1],
[0, 1, 1],
[1, 0, 1],
[1, 1, 1]]
Y = [[0, 1],
[1, 1],
[1, 0],
[0, 1]]
Xtest = np.array([[1, 1, 1],
[0, 1, 1],
[1, 0, 1],
[0, 1, 1]])
# Build neural network
net = tflearn.input_data(shape=[None, 3])
net = tflearn.fully_connected(net, 32, activation='sigmoid')
net = tflearn.fully_connected(net, 32, activation='sigmoid')
net = tflearn.fully_connected(net, 2, activation='softmax')
net = tflearn.regression(net, optimizer='adam')
# Define model
model = tflearn.DNN(net)
# Start training (apply gradient descent algorithm)
model.fit(X, Y, n_epoch=5000, batch_size=16, show_metric=True)
pred = model.predict(Xtest)
for i in range(4):
print(pred[i][0])
输出应该是: [0, 1, 1, 1]
Training Step: 4999 | total loss: 0.50493 | time: 0.004s
| Adam | epoch: 4999 | loss: 0.50493 - acc: 0.7813 -- iter: 4/4
--
0.01631585881114006
0.4872587323188782
0.9684665203094482
0.019177177920937538