是否有使用一年滚动窗口执行 OLS 的特定方法?例如:
训练集:1970-1990,测试集:1991
训练集:1970-1991,测试集:1992
. . .
训练集:1970-2009,测试集:2010
我尝试执行以下操作,但我有一个巨大的数据框,所以它不起作用。
for i in range(1989, 2010):
print(i)
train = df[df['year'] <= i]
test = df[df['year'] == i+1]
x_train = train[train_columns]
y_train = train[column]
x_test = test[train_columns]
y_test = test[column]
model = sm.OLS(y_train, x_train) #missing = "drop"
results = model.fit()
y_pred = results.predict(x_test)