產生預測並計算 RMSE
既然我們已經在資料上訓練好模型,並透過交叉驗證完成調參,現在就來看看它在 test 資料框上的表現。為此,我們會計算 RMSE。
補充說明:在這個資料集上產生測試預測需要超過數分鐘。因此,我們已先行產生測試預測,並提供為名為 test_predictions 的資料框。供你參考,它是用以下程式碼產生的:test_predictions = best_model.transform(test)。
本練習屬於課程
使用 PySpark 打造推薦引擎
練習說明
- 資料框
test_predictions包含我們先前以test集合所建立、並經過交叉驗證的 ALS 模型所生成的預測。使用.show()方法檢視它,看看預測是否接近。 - 使用你先前建立的
evaluator,對產生的test_predictions呼叫.evaluate()方法來計算RMSE。將結果命名為RMSE。 - 列印
RMSE。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# View the predictions
test_predictions.____()
# Calculate and print the RMSE of test_predictions
RMSE = evaluator.____(____)
print(____)