小编Nik*_*kov的帖子

Python:ValueError 太多值无法解压(预期为 2)

我正在尝试通过 GridSearchCV 找到最佳的 xgboost 模型,并且作为 cross_validation 我想使用 4 月的目标数据。这是代码:

    x_train.head()
Run Code Online (Sandbox Code Playgroud)

x_train

    y_train.head()
Run Code Online (Sandbox Code Playgroud)

y_train

    from sklearn.model_selection import GridSearchCV
    from sklearn.model_selection import train_test_split
    from sklearn.metrics import mean_squared_error
    from sklearn.metrics import make_scorer
    from sklearn.ensemble import RandomForestRegressor
    from sklearn.model_selection import TimeSeriesSplit
    import xgboost as xg

    xgb_parameters={'max_depth':[3,5,7,9],'min_child_weight':[1,3,5]}
    xgb=xg.XGBRegressor(learning_rate=0.1, n_estimators=100,max_depth=5, min_child_weight=1, gamma=0, subsample=0.8, colsample_bytree=0.8)
    model=GridSearchCV(n_jobs=2,estimator=xgb,param_grid=xgb_parameters,cv=train_test_split(x_train,y_train,test_size=len(y_train['2016-04':'2016-04']), random_state=42, shuffle=False),scoring=my_func)
    model.fit(x_train,y_train)
    model.grid_scores_
    model.best_params_
Run Code Online (Sandbox Code Playgroud)

但是我在训练模型时遇到了这个错误。

错误

有人可以帮我解决这个问题吗?或者有人可以建议我如何分割非洗牌数据来训练/测试以验证上个月的模型?

感谢您的帮助

python machine-learning cross-validation grid-search train-test-split

3
推荐指数
1
解决办法
9609
查看次数