问题描述
我正在尝试为数据帧创建滚动 OLS,然后评估预测的准确性。我正在查看 StatsModel Rolling OLS(代码片段 1)和 pyfinance 滚动(片段 2)。但我也想不通。
请注意,对于 pyfinance,我能够获得 y_pred,但现在我的实际和预测的 df 长度不同,并且不知道如何解决这个问题。
最终目的是计算预测的均方误差。
感谢任何帮助。
- Statsmodel RollingOLS:
model = RollingOLS(y,X,window=20)
rres = model.fit()
rres.params.tail()
- pyfinance 滚动 OLS:
rolling = ols.PandasRollingOLS(y=y,x=X,window=50)
y_pred = rolling.predicted
y_pred
y_pred 的输出:
end subperiod
5 0 84.901667
1 84.703698
2 85.292206
3 85.398094
4 85.843465
...
1762 1758 702.263867
1759 715.051351
1760 716.051640
1761 713.909576
1762 709.269281
Name: predicted,Length: 10548,dtype: float64
y 的输出:
actual
0 84.900002
1 84.784004
2 85.229996
3 85.271996
4 85.955246
... ...
1758 701.869995
1759 715.479980
1760 715.090698
1761 715.280029
1762 708.306580
1763 rows × 1 columns
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)