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

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

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

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

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

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