【问题标题】:ValueError("Found input variables with inconsistent numbers of" ValueError: Found input variables with inconsistent numbers of samples: [10725, 3575]ValueError(“找到数量不一致的输入变量” ValueError:找到样本数量不一致的输入变量:[10725, 3575]
【发布时间】:2021-02-17 02:23:03
【问题描述】:

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

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

这是我的代码 sn-p:

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

【问题讨论】:

    标签: python valueerror train-test-split


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2020-11-03
      • 2019-03-22
      • 2021-06-20
      • 2018-06-25
      • 2018-04-13
      • 2018-12-04
      • 2021-05-31
      • 2020-08-19
      • 2021-09-12
      相关资源
      最近更新 更多