gpt4 book ai didi

python-3.x - 如何修复构建神经网络时出现的以下错误?

转载 作者:行者123 更新时间:2023-11-30 09:52:06 25 4
gpt4 key购买 nike

您好,我正在更新以下功能:

def train(self, features, targets):

这个想法是让我的在线类(class)的待办事项我尝试过:

# TODO: Output error - Replace this value with your calculations.
error = y - final_outputs # Output layer error is the difference between desired target and actual output.

# TODO: Backpropagated error terms - Replace these values with your calculations.
output_error_term = error * final_outputs * (1 - final_outputs)

# TODO: Calculate the hidden layer's contribution to the error
hidden_error = np.dot(output_error_term, self.weights_hidden_to_output)

# TODO: Backpropagated error terms - Replace these values with your calculations.
hidden_error_term = hidden_error * hidden_outputs * (1 - hidden_outputs)

但是我得到了:

..FFE
======================================================================
ERROR: test_train (__main__.TestMethods)
----------------------------------------------------------------------
Traceback (most recent call last):
File "<ipython-input-11-90579d706c92>", line 41, in test_train
network.train(inputs, targets)
File "<ipython-input-9-596e703ab9b6>", line 65, in train
hidden_error = np.dot(output_error_term, self.weights_hidden_to_output)
ValueError: shapes (1,) and (2,1) not aligned: 1 (dim 0) != 2 (dim 0)

======================================================================
FAIL: test_data_path (__main__.TestMethods)
----------------------------------------------------------------------
Traceback (most recent call last):
File "<ipython-input-11-90579d706c92>", line 20, in test_data_path
self.assertTrue(data_path.lower() == 'bike-sharing-dataset/hour.csv')
AssertionError: False is not true

======================================================================
FAIL: test_run (__main__.TestMethods)
----------------------------------------------------------------------
Traceback (most recent call last):
File "<ipython-input-11-90579d706c92>", line 56, in test_run
self.assertTrue(np.allclose(network.run(inputs), 0.09998924))
AssertionError: False is not true

----------------------------------------------------------------------
Ran 5 tests in 0.005s

FAILED (failures=2, errors=1)

这是完整的代码,我下载了我的 ipython 笔记本来显示我的完整代码:

https://gist.github.com/anonymous/e7a816ef0526d41fbdb63a0aa6c27712

我非常感谢您为解决此问题提供的支持,非常感谢您的支持。

这是数据: https://gist.github.com/anonymous/31340c38a3fd8e175bf0054c7c005d2b

非常感谢您的支持。

最佳答案

对于

hidden_error = np.dot(output_error_term, self.weights_hidden_to_output)

记住点积要求第一个操作数的列数与第二个操作数的行数匹配。你有 (1,1) X (2,1)所以第二个操作数的行数应该是 1 ,这意味着你需要:

(1,1)X(1,2)

这意味着你需要转置第二个操作数,尝试:

hidden_error = np.dot(output_error_term, self.weights_hidden_to_output.T)

但我认为修复此错误后,您会发现由于形状不一致而出现类似的错误。操作您的操作数以匹配第一个操作数的列和第二个操作数的行。

关于python-3.x - 如何修复构建神经网络时出现的以下错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43531511/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com