開始使用免費開始

使用 TensorFlow 訓練神經網路

在前一個練習中,你已定義模型 model(w1, b1, w2, b2, features) 與損失函式 loss_function(w1, b1, w2, b2, features, targets),兩者在本練習中都可直接使用。你現在要訓練該模型,接著用測試集(包含 test_featurestest_targets,已提供給你)來預測違約結果並評估效能。可訓練變數為 w1b1w2b2。此外,以下作業也已為你匯入:keras.activations.relu()keras.layers.Dropout()

本練習屬於課程

Python 的 TensorFlow 入門

檢視課程

練習說明

  • 設定最佳化器執行最小化。
  • loss_function() 參數出現的順序,將 4 個可訓練變數加入 var_list
  • 使用模型與 test_features 來預測 test_targets 的值。

動手互動練習

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

# Train the model
for j in range(100):
    # Complete the optimizer
	opt.____(lambda: loss_function(w1, b1, w2, b2), 
                 var_list=[____, ____, ____, ____])

# Make predictions with model using test features
model_predictions = model(w1, b1, w2, b2, ____)

# Construct the confusion matrix
confusion_matrix(test_targets, model_predictions)
編輯並執行程式碼