x_train, x_test = train_test_split(x, test_size = 0.3,random_state=250)
y_train, y_test = train_test_split(y, test_size = 0.3,random_state=250)
这是使同一个人在x_testand 和 andy_test中x_train重合的方法y_train吗?
x_train, x_test = train_test_split(x, test_size = 0.3,random_state=250)
y_train, y_test = train_test_split(y, test_size = 0.3,random_state=250)
这是使同一个人在x_testand 和 andy_test中x_train重合的方法y_train吗?
train_test_split内置此功能。只需在第一次传递所有数据,例如:
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.3, random_state=250)
from sklearn.model_selection import train_test_split
x = list(range(100))
y = list(range(100, 200))
x_train, x_test, y_train, y_test = train_test_split(
x, y, test_size=0.3, random_state=250)
assert(all(xx == yy - 100 for xx, yy in zip(x_train, y_train)))
assert(all(xx == yy - 100 for xx, yy in zip(x_test, y_test)))
我建议使用索引将数据集拆分为训练并测试特征和目标。