您只需要将拆分的可迭代对象传递给GridSearchCV。此拆分应采用以下格式:
[ (split1_train_idxs, split1_test_idxs), (split2_train_idxs, split2_test_idxs), (split3_train_idxs, split3_test_idxs), ...]
groups = df.groupby(df.date.dt.year).groups# {2012: [0, 1], 2013: [2], 2014: [3], 2015: [4, 5]}sorted_groups = [value for (key, value) in sorted(groups.items())] # [[0, 1], [2], [3], [4, 5]]cv = [(sorted_groups[i] + sorted_groups[i+1], sorted_groups[i+2]) for i in range(len(sorted_groups)-2)]
看起来像这样:
[([0, 1, 2], [3]), # idxs of first split as (train, test) tuple ([2, 3], [4, 5])] # idxs of second split as (train, test) tuple
然后,您可以执行以下 *** 作:
GridSearchCV(estimator, param_grid, cv=cv, ...)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)