可视化模型评分随时间的波动
既然您已经评估了每个系数的波动性,我们也来对模型的性能(评分)做同样的分析。回顾一下,TimeSeriesSplit 对象会为每个测试集使用时间上更晚的索引。这意味着,您可以把验证得到的"评分"当作一个时间序列。通过随时间可视化这些评分,您就能观察模型性能如何随时间变化。
线性回归模型对象的实例存储在 model,交叉验证对象在 cv,数据在 X 和 y。
本练习是课程的一部分
Python 中的时间序列机器学习
交互式实操练习
通过完成这段示例代码来试试这个练习。
from sklearn.model_selection import cross_val_score
# Generate scores for each split to see how the model performs over time
scores = cross_val_score(model, X, y, cv=cv, scoring=my_pearsonr)
# Convert to a Pandas Series object
scores_series = pd.Series(scores, index=times_scores, name='score')
# Bootstrap a rolling confidence interval for the mean score
scores_lo = scores_series.____(20).aggregate(partial(____, percentiles=2.5))
scores_hi = scores_series.____(20).aggregate(partial(____, percentiles=97.5))