我不知道为什么在我的代码不起作用的时候,我肯定以前没问题
我试图使用简单的StratifiedShuffleSplit
,但它不起作用
代码:
from sklearn.model_selection import StratifiedShuffleSplit
print(data_x.shape)`
(100,1)
print(data_y.shape)
(100,28)
考虑到我的数据是多y标签
^{pr2}$我明白了
错误:
ValueError: The least populated class in y has only 1 member, which is too few. The minimum number of groups for any class cannot be less than 2.`
有人能帮帮我吗?在
Python3.6-水蟒
选中
data.column_name.value_counts()
它将告诉您number of samples for a category
。但正如error所说,你对一个类别只有一个观察值。如果一个category
只有一个观察值,那么应该删除该观察值。保留一个不会产生任何影响,也不会为它添加更多的数据category
。在显然,在将数据划分为培训和测试样本时,您犯了一个错误。在
您可以通过设置
StratifiedShuffleSplit()
的参数来解决这个问题, 作为n_splits=classnum, test_size=testRatio,train_size=1-testRatio, random_state=0
。在或者,您可以事先仔细尝试并拆分培训和测试样本,然后将其提供给
StratifiedShuffleSplit()
。在相关问题 更多 >
编程相关推荐