gpt4 book ai didi

python - sklearn.model_selection.GroupShuffleSplit 不会按照预期产生分割

转载 作者:太空宇宙 更新时间:2023-11-03 21:12:41 24 4
gpt4 key购买 nike

因此,我需要使用预定义的组生成测试/训练/验证拆分。我不想使用 LeavePGroupsOut 因为我需要根据我想要的百分比将数据分离到训练和验证集中。在GroupShuffleSplit的文档中,对于test_size参数,是这样说的:

test_size : float, int, None, optional If float, should be between 0.0 and 1.0 and represent the proportion of the dataset to include in the test split. If int, represents the absolute number of test samples. If None, the value is set to the complement of the train size. By default, the value is set to 0.2. The default will change in version 0.21. It will remain 0.2 only if train_size is unspecified, otherwise it will complement the specified train_size.

但是,事实并非如此,如以下代码所示:

tr, ts = next(GroupShuffleSplit(n_splits=1, test_size=3).split(TR_set, groups=tr_groups))
print(tr)
print(ts)

例如打印出:

[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
18 19 20 21 22 23 24 25 28 29 30 31 32 33 34 35 36 37
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 91 92 93
99 101 102 103 104 105 106 107]
[ 26 27 89 90 94 95 96 97 98 100]

正如您在上面看到的,测试大小不是 3,而是大于 3。情况几乎总是如此。我检查了索引组。显然,如果test_size是一个整数,它代表的是测试组的绝对数量,而不是样本数。我认为该文档具有误导性。

此外,当 test_size 为 float 时,它大多不考虑指定的比率。这可能是由于组中的样本大小不相等,但必须有一个注释/警告来指定在不相等的组大小与 test_size 比率相结合的情况下它遵循什么样的行为。

tr, ts = next(GroupShuffleSplit(n_splits=1, test_size=0.1).split(TR_set, groups=tr_groups))
print(len(tr))
print(len(ts))

给出:

70
38

其中测试大小是整个集合的 35%(应该是 10%)。

所以,要么我遗漏了一些东西,要么文档只是错误的描述。

谢谢。

最佳答案

没有错误,但文档在某些地方不正确。我在 scikit-learn's github page 中打开了一个问题对于这个主题。

关于python - sklearn.model_selection.GroupShuffleSplit 不会按照预期产生分割,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54950675/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com