训练-测试集划分
在本练习中,您将对糖果产量数据集进行训练集与测试集划分。正如您在视频练习中所理解的,这样做的目的是在建模完成后评估模型拟合的质量。
糖果产量数据集已作为 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()