首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >执行XGBClassifier的增量学习

执行XGBClassifier的增量学习
EN

Stack Overflow用户
提问于 2021-03-25 06:59:11
回答 1查看 2.7K关注 0票数 5

在参考了此链接之后,我成功地实现了使用XGBoost的增量学习。我想要建立一个分类器,并需要检查预测概率,即predict_proba()方法。如果我使用XGBoost,这是不可能的。在实现XGBClassifier.fit()而不是XGBoost.train()时,我无法执行增量学习。XGBClassifier.fit()XGBClassifier.fit()参数接受XGBoost,而我想提供XGBClassifier

因为我需要使用XGBClassifier方法,所以可以对predict_proba()进行增量学习吗?

工作守则:

代码语言:javascript
运行
复制
import XGBoost as xgb

train_data = xgb.DMatrix(X, y)
model = xgb.train(
    params = best_params, 
    dtrain = train_data, 
)

new_train_data = xgb.DMatrix(X_new, y_new)
retrained_model = xgb.train(
    params     = best_params, 
    dtrain     = new_train_data, 
    xgb_model  = model
)

以上代码运行良好,但没有retrained_model.predict_proba()选项。

非工作守则:

代码语言:javascript
运行
复制
import XGBoost as xgb

xgb_model = xgb.XGBClassifier(**best_params)
xgb_model.fit(X, y)

retrained_model = xgb.XGBClassifier(**best_params)
retrained_model.fit(X_new, y_new, xgb_model = xgb_model)

上面的代码不起作用,因为它期望加载XGBoost模型或Booster instance XGBoost模型。

错误跟踪:

代码语言:javascript
运行
复制
[11:27:51] WARNING: ../src/learner.cc:1061: Starting in XGBoost 1.3.0, the default evaluation metric used with the objective 'binary:logistic' was changed from 'error' to 'logloss'. Explicitly set eval_metric if you'd like to restore the old behavior.
Traceback (most recent call last):
  File "/project/Data_Training.py", line 530, in train
    retrained_model.fit(X_new, y_new, xgb_model = xgb_model)
  File "/home/user/.local/lib/python3.6/site-packages/xgboost/core.py", line 422, in inner_f
    return f(**kwargs)
  File "/home/user/.local/lib/python3.6/site-packages/xgboost/sklearn.py", line 915, in fit
    callbacks=callbacks)
  File "/home/user/.local/lib/python3.6/site-packages/xgboost/training.py", line 236, in train
    early_stopping_rounds=early_stopping_rounds)
  File "/home/user/.local/lib/python3.6/site-packages/xgboost/training.py", line 60, in _train_internal
    model_file=xgb_model)
  File "/home/user/.local/lib/python3.6/site-packages/xgboost/core.py", line 1044, in __init__
    raise TypeError('Unknown type:', model_file)
TypeError: ('Unknown type:', XGBClassifier(base_score=0.5, booster='gbtree', colsample_bylevel=1,
              colsample_bynode=1, colsample_bytree=1, gamma=0, gpu_id=-1,
              importance_type='gain', interaction_constraints='',
              learning_rate=1, max_delta_step=0, max_depth=3,
              min_child_weight=1, missing=nan, monotone_constraints='()',
              n_estimators=100, n_jobs=32, num_parallel_tree=1, random_state=0,
              reg_alpha=0, reg_lambda=1, scale_pos_weight=1, subsample=0.7,
              tree_method='exact', validate_parameters=1, verbosity=None))
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-25 18:17:03

从医生那里:

xgb_model -存储的XGBoost模型或“Booster”实例的文件名。要在培训前加载XGBoost模型(允许继续培训)。

因此,您应该能够使用xgb_model.get_booster()检索底层Booster实例并传递该实例。

此外,您还可以从本机xgboost API中获得预测的概率;Booster.predictobjective='binary:logistic'时返回概率。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66794560

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档