开发者社区> 问答> 正文

train_test_split:ValueError

我目前正在尝试计算特定多项式回归模型的均方误差。但是,当我运行train_test_split时,我收到一条错误消息:

ValueError: too many values to unpack (expected 2)

这是我编写的代码:

def mse(X, y, degree, model):
    X_train, y_train = train_test_split(X, y, test_size=0.6, random_state=10)
    train_errors = []
    for m in range(1, len(X_train)):
        model.fit(X_train[:m], y_train[:m])
        y_train_predict = model.predict(X_train[:m])
        mse = train_errors.append(mean_squared_error(y_train[:m], y_train_predict))
    return mse

我不确定为什么会出现此错误,或者我可以进行哪些更改以使代码正常工作!任何意见,将不胜感激!

问题来源:stackoverflow

展开
收起
is大龙 2020-03-24 12:36:57 456 0
1 条回答
写回答
取消 提交回答
  • train_test_split也返回测试样本:

    X_train, X_test, y_train, y_test = train_test_split(
            X, y, test_size=0.6, random_state=10)
    

    回答来源:stackoverflow

    2020-03-24 12:37:04
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
40 Must know Questions to test 立即下载
40 Must Know Questions to test 立即下载
Constrained Output Embeddings for End-to-End Code-Switching Speech Recognition with Only Monolingual Data 立即下载