評估預測模型
進入評估時間!你在前一個練習中訓練的相同 LSTM 網路,已替你再訓練了幾個 epoch,並以 net 提供。
你的任務是使用均方誤差(Mean Squared Error)評估指標在測試資料集上評估它(torchmetrics 已經替你匯入)。來看看模型表現如何!
本練習屬於課程
Intermediate Deep Learning with PyTorch
練習說明
- 定義均方誤差評估指標並指定給
mse。 - 將輸入序列傳入
net,並在指定給outputs前先對結果做 squeeze。 - 計算測試指標的最終數值並指定給
test_mse。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Define MSE metric
mse = ____
net.eval()
with torch.no_grad():
for seqs, labels in dataloader_test:
seqs = seqs.view(32, 96, 1)
# Pass seqs to net and squeeze the result
outputs = ____
mse(outputs, labels)
# Compute final metric value
test_mse = ____
print(f"Test MSE: {test_mse}")