Spot the validation-strategy bug when evaluating a model on time-ordered data.
Codepython
from sklearn.model_selection import KFold, cross_val_score
from sklearn.linear_model import LinearRegression
import numpy as np
# X is ordered by timestamp (oldest -> newest), y is next-day price
X = np.load('daily_features.npy')
y = np.load('next_day_price.npy')
model = LinearRegression()
cv = KFold(n_splits=5, shuffle=True, random_state=42)
scores = cross_val_score(model, X, y, cv=cv, scoring='r2')
print('Mean R2:', scores.mean())
This forecasting evaluation gives overly optimistic scores. What is the bug?