小编Han*_*taa的帖子

sklearn的train_test_split中的“分层”参数无法正常工作?

stratifytrain_test_split()scikit-learn函数中的参数有问题。这是一个具有相同问题的虚拟示例,该问题随机出现在我的数据上:

from sklearn.model_selection import train_test_split
a = [1, 0, 0, 0, 0, 0, 0, 1]
train_test_split(a, stratify=a, random_state=42)
Run Code Online (Sandbox Code Playgroud)

返回:

[[1, 0, 0, 0, 0, 1], [0, 0]]
Run Code Online (Sandbox Code Playgroud)

它不应该在测试子集中也选择“ 1”吗?从我多么希望train_test_split()stratify工作就应该返回类似:

[[1, 0, 0, 0, 0, 0], [0, 1]]
Run Code Online (Sandbox Code Playgroud)

对于某些值,会发生这种情况random_state,而对于其他值,它会正常工作;但是我每次必须分析数据时都无法搜索它的“正确”值。

我有python 2.7和scikit-learn 0.18。

python python-2.7 scikit-learn

2
推荐指数
1
解决办法
3076
查看次数

标签 统计

python ×1

python-2.7 ×1

scikit-learn ×1