首页 > 解决方案 > 如何使用 MultiOutputRegressor 的 XGBoost 继续学习?

问题描述

我正在尝试使用继续训练来训练多输出 XGBoost 回归模型,但出现此错误:

TypeError: ('Unknown type:', MultiOutputRegressor(estimator=XGBRegressor(base_score=None, booster=None)

我的代码如下:

params = {
    'n_estimators':2000,
    'learning_rate':0.001,
    'max_depth':6,
    'min_child_weight': 1,
    'eta':.3,
    'subsample': 1,
    'colsample_bytree': 1,
    'objective':'reg:squarederror',}
    path = os.path.join('.', "xgb_model_direct.pkl")

for i, (x_batch, y_batch, _, _, _, _) in enumerate(pca_train_ds):

    # transform X: (batch_size, num_components, input_horizon_steps) --> 
    # (batch_size,  num_components*input_horizon_steps) 
    x_batch = x_batch.numpy().reshape(x_batch.shape[0], -1)
    
    # transform Y: (batch_size, num_components) --> 
    #(batch_size , num_components) 
    y_batch = y_batch.numpy().reshape(y_batch.shape[0], -1)

    # define model
    model = xgb.XGBRegressor(**params)
    
    # define the direct multioutput wrapper model
    wrapper = MultiOutputRegressor(model)

 if i==0:
    wrapper.fit(x_batch, y_batch)
    # save model to file
    joblib.dump(wrapper, path)
else:
    # load model from file
    loaded_model = joblib.load(path)
    wrapper.fit(x_batch, y_batch, xgb_model=loaded_model)        

标签: python-3.xmachine-learningregressionxgboostmini-batch

解决方案


推荐阅读