ValueError(“找到数量不一致的输入变量” ValueError:找到样本数量不一致的输入变量:[10725,3575]

时间:2020-11-04 11:31:49

标签: python valueerror train-test-split

我已经被这个错误困扰了很长时间了。每当我运行此代码时,都会出现以下错误:

raise ValueError("Found input variables with inconsistent numbers of "ValueError: Found input variables with inconsistent numbers of samples: [10725, 3575]

这是我的代码段:

n_classes = len(classes)

X_train, X_test, y_train, y_test = train_test_split(X, Y, random_state=0, test_size = 0.75)

X_train_scale = X_train/255.0
X_test_scale = X_test/255.0

1 个答案:

答案 0 :(得分:0)

您收到此错误,是因为 train_test_split 要求X和Y必须具有相同的长度,而在这里情况并非如此。实际上:
X.shape[0] == 10725Y.shape[0] == 3575

要解决此问题,您必须重塑X。这是我的建议:
X.reshape(Y.shape[0], -1)