【问题标题】:too many values to unpack (expected 3)太多的值要解压(预期 3)
【发布时间】:2019-09-08 04:40:30
【问题描述】:

在使用 python 将数据拆分为训练和测试时,我收到以下错误

" too many values to unpack (expected 3)"

这是我的代码:

from sklearn.model_selection import train_test_split
X_train, X_test, y_train = train_test_split(features,prices, test_size=0.2, random_state=10)
print("Training and testing split was succesful")

这是预期的输出:'Training and testing split was successful'

【问题讨论】:

  • 能否提供更完整的错误日志?
  • 我已经解决了,谢谢

标签: python logistic-regression


【解决方案1】:

看起来你错过了 y_test。

试试这个:

X_train, X_test, y_train, y_test = train_test_split(features,prices, test_size=0.2, random_state=10) 

【讨论】:

  • 刚刚意识到......谢谢:)
【解决方案2】:

这是sklearn中train_test_split的文档:sklearn.model_selection.train_test_split

这是回报:

拆分:列表,长度=2 * len(数组)

包含输入的训练测试拆分的列表。

如果您输入特征和价格,这意味着您输入了两个输入,每个输入将分为两个部分,训练和测试。所以为了获取它们,你应该使用X_train, X_test, y_train, y_test,但是你错过了最后一个参数。

您可以像这样更正您的代码:

from sklearn.model_selection import train_test_split 

X_train, X_test, y_train, y_test = train_test_split(features,prices, test_size=0.2, random_state=10) 
print("Training and testing split was successful")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-19
    • 2019-01-13
    • 2019-12-28
    • 2021-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多