使用 TensorFlow 訓練神經網路
在前一個練習中,你已定義模型 model(w1, b1, w2, b2, features) 與損失函式 loss_function(w1, b1, w2, b2, features, targets),兩者在本練習中都可直接使用。你現在要訓練該模型,接著用測試集(包含 test_features 與 test_targets,已提供給你)來預測違約結果並評估效能。可訓練變數為 w1、b1、w2、b2。此外,以下作業也已為你匯入: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)