【问题标题】:xgboost.core.XGBoostError: need to call fit beforehand - when trying to predict through a pickled modelxgboost.core.XGBoostError:需要预先调用 fit - 尝试通过腌制模型进行预测时
【发布时间】:2019-01-30 04:05:32
【问题描述】:

我创建了一个 XGBoost 分类器,并使用 joblib 以 dat 文件格式转储了 python 文件。

我可以使用 joblib 加载它,但是当我尝试使用加载的模型来预测新数据时,我看到了错误

 xgboost.core.XGBoostError: need to call fit beforehand

我训练的原始模型是:

 XGBClassifier(base_score=0.5, booster='gbtree', colsample_bylevel=1,
   colsample_bytree=0.6, eval_metric='error', gamma=0,
   learning_rate=0.125, max_delta_step=0, max_depth=8,
   min_child_weight=1, missing=None, n_estimators=600, n_jobs=1,
   nthread=None, objective='binary:logistic', random_state=0,
   reg_alpha=0.2, reg_lambda=0.8, scale_pos_weight=1, seed=None,
   silent=True, subsample=0.8)

腌制模型是:

XGBClassifier(base_score=0.5, booster='gbtree', colsample_bylevel=1,
   colsample_bytree=1, gamma=0, learning_rate=0.1, max_delta_step=0,
   max_depth=3, min_child_weight=1, missing=None, n_estimators=100,
   n_jobs=1, nthread=None, objective='binary:logistic',random_state=0,
   reg_alpha=0, reg_lambda=1, scale_pos_weight=1, seed=None,
   silent=True, subsample=1)

错误的任何原因以及为什么尽管我保存和加载相同的模型但两者都不同?

【问题讨论】:

  • 您能否提供您的代码 sn-ps 适合和腌制模型的位置,然后加载和预测的位置?仅仅看到模型并不能真正帮助诊断任何事情

标签: python xgboost


【解决方案1】:

使用 fit 重新运行模型,保存,然后像往常一样加载管道文件。

保存模型

joblib.dump(pipeline, "xgb1.joblib.dat")

从文件中加载模型

loaded_model = joblib.load("xgb1.joblib.dat")

以这种方式加载模型后,错误将消失。它对我有用。

【讨论】:

    猜你喜欢
    • 2019-02-17
    • 1970-01-01
    • 1970-01-01
    • 2021-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-24
    • 2015-12-19
    相关资源
    最近更新 更多