python-3.x - 在 ScikitLearn 的 GroupKFold 中出现错误消息:ValueError: too many values to unpack (expected 2)
问题描述
在使用 scikit-learn 中的 GroupKFold 方法时,我收到一条错误消息,鉴于文档,我无法理解。
错误信息是:
ValueError: too many values to unpack (expected 2)
该文档指出:
对于一个可重现的例子:
from sklearn.model_selection import GroupKFold
X1 = np.random.randint(1, 10, size = (100, 2))
groups1 = np.random.choice([1,2,3, 4, 5], size = 100, p = [.15, .2, .3, .15, .2])
gkf1 = GroupKFold(5)
train, test = gkf1.split(X = X1, groups = groups1 )
这会产生以下错误消息:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-56-911681dea183> in <module>
8 gkf1 = GroupKFold(5)
9
---> 10 train, test = gkf1.split(X = X1, groups = groups1 )
ValueError: too many values to unpack (expected 2)
解决方案
该split
函数返回一个生成器。您将不得不遍历生成器以获取训练组和测试组。
如示例所示
for train_index, test_index in gkf1.split(X, y, groups):
推荐阅读
- msbuild - Azure DevOps - 将 MSBuild 属性作为参数传递给其他构建任务
- javascript - 通过 JS 获取倒数第二个 HTML 元素
- r - 根据因子条件在 R 中插入行
- sqlite - 如何在 initstate 中访问未来值?
- python - python pandas - 获取两个数据帧之间的匹配和不匹配记录
- python - Tensorflow 序列到 LSTM 序列
- python - 如果是的话,将关系数据库表存储为弹性搜索中的不同索引是否很好,那么如何在索引中传递关系
- javascript - 如何获取将 servlet 返回到 ajax 的特定字段?
- iframe - Youtube 嵌入显示不需要的顶部栏,即使 showinfo=0
- c - 关于 C 函数