python-3.x - 如何使用 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)
解决方案
推荐阅读
- javascript - 我想创建一个包含 php vars 的文件 .json?
- c# - 当使用 { value } 语法初始化 ICollection 属性而不指定集合类型(数组、列表等)时会发生什么?
- node.js - AWS SNS 不能从 lambda 工作,但可以在本地工作
- javascript - 我的导航切换仅适用于两个页面,但不适用于主页
- webpack - webpack.config.js:意外字符'@'
- python - 你能在 matplotlib 中创建非均匀的可迭代图吗
- javascript - 将 JS DOM 元素添加到空的 html shell
- javascript - vis.js/Javascript/React:从数据库中获取组
- typescript - 返回泛型类型的“类型”
- html - 如何在 Mat Chip Angular 中编辑 Mat Ripples 属性