開始使用免費開始

進行預測

你在上一個程式練習中訓練好的網路已儲存為 model。用來進行預測的新資料以 NumPy 陣列形式存放在 pred_data。請使用 model 對這筆新資料進行預測。

在這個練習中,你的預測會是機率。這是資料科學家與同事溝通預測結果時最常用的方式。

本練習屬於課程

Python 深度學習入門

檢視課程

練習說明

  • pred_data 上呼叫模型的 .predict() 方法來建立你的預測。
  • 使用 NumPy 索引,找到對應於預測「存活為 True」之機率的欄。這是 predictions 的第 2 個欄位(索引為 1)。將結果存成 predicted_prob_true,並將它印出。

動手互動練習

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

# Specify, compile, and fit the model
model = Sequential()
model.add(Dense(32, activation='relu', input_shape = (n_cols,)))
model.add(Dense(2, activation='softmax'))
model.compile(optimizer='sgd', 
              loss='categorical_crossentropy', 
              metrics=['accuracy'])
model.fit(predictors, target)

# Calculate predictions: predictions
predictions = ____

# Calculate predicted probability of survival: predicted_prob_true
predicted_prob_true = ____

# Print predicted_prob_true
print(predicted_prob_true)
編輯並執行程式碼