ANN教程错误率未降低

时间:2018-08-26 01:21:18

标签: python machine-learning

在这里浏览了流行的神经网络教程之后: https://www.youtube.com/watch?v=h3l4qz76JhQ

我相信我已经完全按照本教程进行了学习,但是结果如下:

Error:0.496410031903
Error:0.499999652828
Error:0.499999831726
Error:0.49999988989
Error:0.499999918514
Error:0.499999935488
Output after training:
[[ 0.50000107]
 [ 0.50000133]
 [ 0.50000142]
 [ 0.50000147]]

这与Siraj的完美输出相差甚远

这是我的代码:

def nonlin(x, deriv=False):
    if (deriv == True):
        return x*(1-x)
    return 1/(1+np.exp(-x))

X = np.array([[0,0,1],[0,1,1],[1,0,1],[1,1,1]])
y = np.array([[0],[1],[1],[0]])

np.random.seed(1)

syn0 = 2*np.random.random((3,4)) - 1
syn1 = 2*np.random.random((4,1)) - 1

for j in range(60000):

    l0 = X
    l1 = nonlin(np.dot(l0, syn0))
    l2 = nonlin(np.dot(l1, syn1))

    l2_error = y - l2

    if (j % 10000 == 0):
        print("Error:" + str(np.mean(np.abs(l2_error))))

    l2_delta = l2_error*nonlin(l2, deriv=True)

    l1_error = l2_delta.dot(syn1.T)

    l1_delta = l1_error + nonlin(l1, deriv=True)

    # update weights
    syn1 += l1.T.dot(l2_delta)
    syn0 += l0.T.dot(l1_delta)

print("Output after training:")
print(l2)

我在评估函数中是否犯了错误,我是否停留在局部最小值上,反向传播部分是否错误,本教程是否错误?

0 个答案:

没有答案