首页 > 解决方案 > 为什么我的 train_test_split 不适用于分层选项?

问题描述

我在下面运行代码以均匀拆分数据,但数据没有按预期拆分。

from sklearn.model_selection import train_test_split
y_train, y_test = train_test_split(label, test_size = 0.5, stratify= label, random_state=1)

它返回:
y_train.shape = (115956,)
y_test.shape = (22,)

特征形状:(123670, 15),
标签形状:(123670,),
label.value_counts() 返回:
0 123578
1 92

如果我删除分层选项,它工作正常。有人知道为什么吗?我感到很困惑。

Scikit-learn==0.23.1

我真的需要帮助,这个问题一直在杀死我:(

标签: scikit-learn

解决方案


推荐阅读