【问题标题】:ValueError: Found input variables with inconsistent numbers of samples: [75, 1]ValueError:发现样本数量不一致的输入变量:[75, 1]
【发布时间】:2017-03-16 07:35:23
【问题描述】:

谁能告诉我这是什么错误以及如何解决(如图所示)

这是错误信息

Traceback (most recent call last):
  File "ep5pipeline.py", line 57, in <module>
    print (accuracy_score(y_test,predictions, normalize = False))
  File "//anaconda/lib/python3.6/site-packages/sklearn/metrics/classification.py", line 172, in accuracy_score
    y_type, y_true, y_pred = _check_targets(y_true, y_pred)
  File "//anaconda/lib/python3.6/site-packages/sklearn/metrics/classification.py", line 72, in _check_targets
    check_consistent_length(y_true, y_pred)
  File "//anaconda/lib/python3.6/site-packages/sklearn/utils/validation.py", line 181, in check_consistent_length
    " samples: %r" % [int(l) for l in lengths])
ValueError: Found input variables with inconsistent numbers of samples: [75, 1]

【问题讨论】:

  • 在堆栈溢出时,我们希望您将代码缩进 4 个空格(大多数编辑器都有一个选项卡宏)然后发布您的源代码(它将在 StackOverflow 上使用语法突出显示来格式化),而不是而不是代码的屏幕截图。原因是,我们喜欢在我们自己的编辑器中调出它,看看是什么改进了功能(我们讨厌不得不从图片中一个字母一个字母地复制文本)。
  • 感谢您的建议。我会改进它:D

标签: python scikit-learn


【解决方案1】:

在函数 predict() 中,return predictions 应该退出“for”迭代。

此外,就像 Neil 所说,最好发布源代码。

【讨论】:

    猜你喜欢
    • 2022-01-16
    • 2021-07-29
    • 2020-11-15
    • 2021-10-09
    • 2020-07-05
    • 2017-06-30
    • 1970-01-01
    • 1970-01-01
    • 2017-09-27
    相关资源
    最近更新 更多