[英]How to split a tuple using train_test_split?
X = (569,30)
y = (569,)
X_train, X_test, y_train, y_test = train_test_split(np.asarray(X),np.asarray(y),test_size = 0.25, random_state=0)
I am expecting output as below:我期待 output 如下:
But i am getting the following warning但我收到以下警告
ValueError: Found input variables with inconsistent numbers of samples: [2, 1]
I know that, i can get the desired output in another way, all the problems found in the online show that lengths of X and y are not same but in my case that's not the problem.我知道,我可以通过另一种方式获得所需的 output,在线发现的所有问题都表明 X 和 y 的长度不一样,但在我的情况下这不是问题。
It seems that you're misunderstanding what train_test_split
does.您似乎误解了
train_test_split
的作用。 It is not expecting the shapes of the input arrays, what it does is to split the input arrays into train and test sets.它不期望输入 arrays 的形状,它所做的是将输入 arrays拆分为训练集和测试集。 So you must feed it the actual arrays, for instace:
所以你必须给它实际的 arrays,例如:
X = np.random.rand(569,30)
y = np.random.randint(0,2,(569))
X_train, X_test, y_train, y_test = train_test_split(np.asarray(X),np.asarray(y),test_size = 0.25, random_state=0)
print(X_train.shape)
print(X_test.shape)
print(y_train.shape)
print(y_test.shape)
(426, 30)
(143, 30)
(426,)
(143,)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.