始める無料で始める

時間経過によるモデルスコアのばらつきを可視化する

各係数のばらつきを評価できたので、次はモデルの性能(スコア)でも同じことを行いましょう。TimeSeriesSplit オブジェクトは、各テストセットで時系列的に後ろのインデックスを使用します。つまり、検証で得られた「スコア」を時系列データとして扱えます。これを時間に沿って可視化すると、モデルの性能が時間とともにどう変化するかを確認できます。

線形回帰モデルのインスタンスは model、交差検証オブジェクトは cv、データは Xy に用意されています。

この演習はコースの一部です

Pythonで学ぶMachine Learningによる時系列データ解析

コースを見る

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

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))
コードを編集して実行