重現驗證分數
你在影片中看過驗證分數與 Public Leaderboard 分數。不過,提供的程式碼範例只針對測試資料。若要取得驗證分數,你需要在保留集上重複相同流程。
本章將使用 New York City Taxi 競賽的資料。任務是預測紐約市計程車車資(fare amount)。競賽指標是均方根誤差(root mean squared error)。
第一個目標是在驗證資料上評估基準模型(Baseline)。你將重現最簡單的基準模型:以 "fare_amount" 的平均值作為預測。回想我們的驗證策略是以 30% 的保留切分,validation_train 作為訓練,validation_test 作為保留的 DataFrame。這兩個都已在你的工作區可用。
本練習屬於課程
用 Python 拿下 Kaggle 競賽
練習說明
- 計算整個
validation_trainDataFrame 中"fare_amount"的平均值。 - 將此樸素預測值指定給所有保留集的預測,並存到
"pred"欄位中。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
import numpy as np
from sklearn.metrics import mean_squared_error
from math import sqrt
# Calculate the mean fare_amount on the validation_train data
naive_prediction = np.____(____['____'])
# Assign naive prediction to all the holdout observations
validation_test['pred'] = ____
# Measure the local RMSE
rmse = sqrt(mean_squared_error(validation_test['fare_amount'], validation_test['pred']))
print('Validation RMSE for Baseline I model: {:.3f}'.format(rmse))