開始使用免費開始

用程式實作:權重變動如何影響準確度

現在你要在一個真實的網路裡調整權重,並觀察它們如何影響模型準確度!

先看看這個神經網路: Ch2Ex4

其權重已預先載入為 weights_0。你在本練習的任務是只更新 weights_0 中的「一個」權重,產生 weights_1,使預測結果完美(也就是預測值等於 target_actual:3)。

必要時可用紙筆嘗試不同的組合。你會使用 predict_with_network() 函式,它的第一個參數是資料陣列,第二個參數是權重。

本練習屬於課程

Python 深度學習入門

檢視課程

練習說明

  • 建立名為 weights_1 的權重字典,將 weights_0 中的「1」個權重做修改(你只需要對 weights_0 做 1 次編修即可得到完美預測)。
  • 使用 predict_with_network() 函式,搭配 input_dataweights_1,取得新的預測結果。
  • model_output_1 減去 target_actual,計算新權重下的誤差。
  • 按下「Submit Answer」查看誤差如何比較!

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# The data point you will make a prediction for
input_data = np.array([0, 3])

# Sample weights
weights_0 = {'node_0': [2, 1],
             'node_1': [1, 2],
             'output': [1, 1]
            }

# The actual target value, used to calculate the error
target_actual = 3

# Make prediction using original weights
model_output_0 = predict_with_network(input_data, weights_0)

# Calculate error: error_0
error_0 = model_output_0 - target_actual

# Create weights that cause the network to make perfect prediction (3): weights_1
weights_1 = {'node_0': [____, ____],
             'node_1': [____, ____],
             'output': [____, ____]
            }

# Make prediction using new weights: model_output_1
model_output_1 = ____

# Calculate error: error_1
error_1 = ____ - ____

# Print error_0 and error_1
print(error_0)
print(error_1)
編輯並執行程式碼