【问题标题】:Expected 2D array, got 1D array instead:预期的 2D 数组,得到 1D 数组:
【发布时间】:2020-12-18 07:47:23
【问题描述】:

我曾经通过使用 GridSearchCV 调整参数来使用线性回归构建模型。 在找到分数的情况下,我无法找到。它表明,

array=[1 1 1 1 1 0 0 0 1 1 0 0 1 0 1 1 1 1 0 1 0 0 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1]
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.

我使用了代码。

model.score(y_pred,y_test)

这是什么问题!!! 和model.score(取什么类型的数据)

y_pred 是一个从回归器给出的单维数组。但它不能带入分数功能。我能做些什么?以及它的解决方案是什么?

【问题讨论】:

    标签: pandas numpy machine-learning data-science linear-regression


    【解决方案1】:

    看起来你已经切换了参数。

    .score() 函数至少需要两个参数。第一个是您需要的任何输入格式的类似数组(在本例中为(n_examples, n_features),第二个是形状为(n_examples,) 的类似数组,包含与这些输入对应的正确目标输出。

    如有疑问,请查看文档。在这种情况下,.score() 的文档字符串会帮助您找到问题。

    【讨论】:

      猜你喜欢
      • 2018-09-16
      • 2018-12-11
      • 2019-06-06
      • 2021-12-28
      • 2021-05-14
      • 2020-11-02
      • 2020-03-19
      • 1970-01-01
      相关资源
      最近更新 更多