我想使用scikit-learn的GridSearchCV确定随机森林模型的一些超参数。我的数据是时间相关的,看起来像这样:
import pandas as pd
train = pd.DataFrame({'date': pd.DatetimeIndex(['2012-1-1', '2012-9-30', '2013-4-3', '2014-8-16', '2015-3-20', '2015-6-30']),
'feature1': [1.2, 3.3, 2.7, 4.0, 8.2, 6.5],
'feature2': [4, 4, 10, 3, 10, 9],
'target': [1,2,1,3,2,2]})
>>> train
date feature1 feature2 target
0 2012-01-01 1.2 4 1
1 2012-09-30 3.3 4 2
2 2013-04-03 2.7 10 1
3 2014-08-16 4.0 3 3
4 2015-03-20 8.2 10 2
5 2015-06-30 6.5 9 2
我该如何实现以下的交叉验证折叠技术?
train:(2012, 2013) - test:(2014)
train:(2013, 2014) - test:(2015)
也就是说,我想使用两年的历史观测数据来训练模型,并在随后的一年测试其准确性。