2017-04-20 67 views
0

你好我更新了以下功能:如何解決以下錯誤建立一個神經網絡?

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) 

這是完整的代碼,我下載我的IPython的筆記本,以顯示我的完整代碼:

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

我真的很感謝支持來克服這個問題非常感謝支持。

這是數據: https://gist.github.com/anonymous/31340c38a3fd8e175bf0054c7c005d2b

非常感謝支持。

回答

1

對於

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) 

但我認爲解決這個錯誤之後,你會發現,因爲形狀不一致的類似的錯誤。操縱你的操作數相匹配,對第一列,在第二行。