如何使用列车测试分割?修复错误n_示例=0

2024-03-28 11:34:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图将正在处理的数据拆分为训练集和测试集,但在使用train_test_split函数时,我得到的错误是n_samples=0

这是我的密码:

X_train, X_test, y_train, y_test = model_selection.train_test_split(summary, labels, test_size=0.35)

摘要和标签是列表,将它们转换为数组后,我得到的形状是:

(1248,)
(1248,)

它们都有1248个值。有人能告诉我为什么它不工作吗?谢谢

错误消息:

With n_samples=0, test_size=0.35 and train_size=None, the resulting train set will be empty. Adjust any of the aforementioned parameters

Tags: the数据函数test密码sizelabelsmodel
1条回答
网友
1楼 · 发布于 2024-03-28 11:34:32

适用于我,请检查此选项是否适用于您:

from sklearn.model_selection import train_test_split
import numpy as np

# dummy examples
summary, labels = np.arange(0,1248), np.arange(0,1248)

X_train, X_test, y_train, y_test = train_test_split(summary, labels, test_size=0.35)

使用字符串列表进行测试

summary, labels = ["hello"]*1248, ["test"]*1248

相关问题 更多 >