Reputation: 1879
Hello I am updating the following function:
def train(self, features, targets):
the idea is to make the todo of my online course I tried this:
# 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)
however I got:
..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)
this is the complete code, I downloaded my notebook of ipython to show my complete code:
https://gist.github.com/anonymous/e7a816ef0526d41fbdb63a0aa6c27712
I really appreciate support to overcome this issue thanks a lot for the support.
this is the data: https://gist.github.com/anonymous/31340c38a3fd8e175bf0054c7c005d2b
thanks a lot for the support.
Upvotes: 0
Views: 382
Reputation: 3534
For
hidden_error = np.dot(output_error_term, self.weights_hidden_to_output)
Remember dot product requires that the number of columns of the first operand ,matches the number of rows of the second operand. You have (1,1) X (2,1) So the number of rows of the second operand should be 1 ,that means you need:
(1,1)X(1,2)
That means you need to transpose the second operand, try:
hidden_error = np.dot(output_error_term, self.weights_hidden_to_output.T)
But i think after fixing this error, you will find similar errors because of shape inconsistencies. Manipulate your operands to match the columns on the first, with the rows in the second.
Upvotes: 1