訓練-測試集切分
在這個練習中,你要把糖果產量資料集切分成訓練集與測試集。就像你在影片練習中所理解的,這麼做是為了在完成後可以評估模型擬合的品質。
糖果產量資料集已經以 candy 載入給你,pyplot 也已經以 plt 載入。
本練習屬於課程
Python 中的 ARIMA 模型
練習說明
- 使用
datetime索引切片,將時間序列切分為訓練集與測試集。訓練集取截至 2006 年底的所有資料,測試集取自 2007 年初之後的所有資料。 - 使用
subplots()函式建立一個pyplot座標軸。 - 使用 DataFrame 的
.plot()方法,將訓練集與測試集畫在座標軸ax上。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Split the data into a train and test set
candy_train = candy.____
candy_test = candy.____
# Create an axis
fig, ax = ____
# Plot the train and test sets on the axis ax
candy_train.____(ax=____)
candy_test.____(ax=____)
plt.show()