栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

scikit-学习交叉验证时间序列数据的自定义拆分

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

scikit-学习交叉验证时间序列数据的自定义拆分

您只需要将拆分的可迭代对象传递给GridSearchCV。此拆分应采用以下格式:

[ (split1_train_idxs, split1_test_idxs), (split2_train_idxs, split2_test_idxs), (split3_train_idxs, split3_test_idxs), ...]

要获取idx,您可以执行以下操作:

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, ...)


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/668428.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号