Python 3.x 如何修复以下错误构建神经元网络?

Python 3.x 如何修复以下错误构建神经元网络?,python-3.x,machine-learning,neural-network,Python 3.x,Machine Learning,Neural Network,您好,我正在更新以下功能: def train(self, features, targets): 我的想法是让我的在线课程成为我的待办事项。我尝试了以下方法: # TODO: Output error - Replace this value with your calculations. error = y - final_outputs # Output layer error is the difference between desired target an

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

def train(self, features, targets):
我的想法是让我的在线课程成为我的待办事项。我尝试了以下方法:

# 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)
.FFE
======================================================================
错误:测试列(\uuuuu main\uuuuuuu.TestMethods)
----------------------------------------------------------------------
回溯(最近一次呼叫最后一次):
文件“”,第41行,在测试列车中
网络培训(输入、目标)
文件“”,第65行,列车中
隐藏错误=np.dot(输出错误项,自权重隐藏到输出)
ValueError:形状(1,)和(2,1)未对齐:1(尺寸0)!=2(尺寸0)
======================================================================
失败:测试\u数据\u路径(\u主\u.TestMethods)
----------------------------------------------------------------------
回溯(最近一次呼叫最后一次):
文件“”,第20行,在测试数据路径中
self.assertTrue(data_path.lower()==“自行车共享数据集/hour.csv”)
断言者错误:False不是true
======================================================================
失败:测试运行(\u主\u.TestMethods)
----------------------------------------------------------------------
回溯(最近一次呼叫最后一次):
文件“”,第56行,正在运行测试
self.assertTrue(np.allclose(网络运行(输入),0.09998924))
断言者错误:False不是true
----------------------------------------------------------------------
在0.005s内运行了5次测试
失败(失败=2,错误=1)
这是完整的代码,我下载了我的ipython笔记本以显示我的完整代码:

我真的很感谢大家对解决这个问题的支持,非常感谢大家的支持

以下是数据:

非常感谢您的支持。

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)
但我认为在修复这个错误后,您会发现类似的错误,因为形状不一致。操纵操作数,使第一个操作数上的列与第二个操作数上的行相匹配