我正在尝试建立一个用于识别三位二进制输入的神经网络。这是我的代码:
import numpy as np
#setting the data note that I skipped [0,1,1] for the test
x = np.array([[0,0,0],
[0,0,1],
[0,1,0],
[1,0,0],
[1,0,1],
[1,1,0],
[1,1,1]])
y = np.array([[0,1,2,4,5,6,7]]).T #note I also skipped 3 for testing
#setting the weight
w = np.random.randn()
#setting the unknown
un_x = np.array([[0,1,1]])
class nn:
#defining back_prop
def back_prop(input, weight):
for i in range(1000000):
output = 1 / (1 + np.exp(-(np.dot(input, weight))))
weight += np.dot(input.T, (y - output) * output * (1 - output))
w = weight
#defining the sigmoid function
def sigmoid(input, weight):
1 / (1 + np.exp(-(np.dot(input, weight))))
#training
nn.back_prop(x, w)
#testing the neural network
print (nn.sigmoid(un_x, w))
当我在终端上运行程序时,我很失望。在
print (nn.sigmoid(un_x, w))
最后的行应该打印一个接近3的数字,但我从终端得到了无响应。我可能需要这个程序的隐藏层,因为这个神经网络可能太复杂了。但是直到我得到终端显示为什么的响应,我才不会打扰。任何帮助将不胜感激。
答案 0 :(得分:3)
我建议发表一份回复声明。有时显而易见的事情会跳过头脑。