how to implement walk forward testing in sklearn?(如何在 sklearn 中实现前向测试?)
问题描述
在 sklearn 中,GridSearchCV 可以将管道作为参数,通过交叉验证找到最佳估计器.然而,通常的交叉验证是这样的:
In sklearn, GridSearchCV can take a pipeline as a parameter to find the best estimator through cross validation. However, the usual cross validation is like this:
为了交叉验证时间序列数据,训练和测试数据通常是这样拆分的:
to cross validate a time series data, the training and testing data are often splitted like this:
也就是说,测试数据应该总是领先于训练数据.
That is to say, the testing data should be always ahead of training data.
我的想法是:
编写我自己的k-fold版本类并将其传递给GridSearchCV,这样我就可以享受管道的便利.问题是让 GridSearchCV 使用指定的训练和测试数据索引似乎很困难.
Write my own version class of k-fold and passing it to GridSearchCV so I can enjoy the convenience of pipeline. The problem is that it seems difficult to let GridSearchCV to use an specified indices of training and testing data.
写一个新的类GridSearchWalkForwardTest,类似于GridSearchCV,正在研究grid_search.py源码,发现有点复杂.
Write a new class GridSearchWalkForwardTest which is similar to GridSearchCV, I am studying the source code grid_search.py and find it is a little complicated.
欢迎提出任何建议.
推荐答案
我认为你可以使用 时间序列拆分 代替您自己的实现或作为实现与您描述的完全相同的 CV 方法的基础.
I think you could use a Time Series Split either instead of your own implementation or as a basis for implementing a CV method which is exactly as you describe it.
经过一番挖掘,似乎有人在 这个 PR 看起来就像你想要的一样.
After digging around a bit, it seems like someone added a max_train_size to the TimeSeriesSplit in this PR which seems like it does what you want.
这篇关于如何在 sklearn 中实现前向测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 sklearn 中实现前向测试?
基础教程推荐
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 包装空间模型 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
