xgboost icon indicating copy to clipboard operation
xgboost copied to clipboard

online predict issue

Open gokunwu opened this issue 10 years ago • 3 comments

I am using xgboost to predict online, but the result I get from online predict interface is diff with the result I get from batch interface, is there any thing I used error?

online predict interface: // implementation of inline functions. inline void Learner::Predict(const SparseBatch::Inst& inst, bool output_margin, std::vector* out_preds, unsigned ntree_limit)

batch predict interface: virtual void Predict(DMatrix* data, bool output_margin, std::vector *out_preds, unsigned ntree_limit = 0, bool pred_leaf = false) const = 0;

gokunwu avatar May 05 '16 01:05 gokunwu

I have encountered this problem too. @tqchen

fanfannothing avatar Jun 27 '16 14:06 fanfannothing

I think this should be a bug, mainly the following part of the code: ~/include/xgboost/learner.h

// implementation of inline functions.
inline void Learner::Predict(const SparseBatch::Inst& inst,
                             bool output_margin,
                             std::vector<bst_float>* out_preds,
                             unsigned ntree_limit) const {
  gbm_->Predict(inst, out_preds, ntree_limit);
  if (out_preds->size() == 1) {
    (*out_preds)[0] += base_score_;
  }
  if (!output_margin) {
    obj_->PredTransform(out_preds);
  }
}

If you can comment conditions about (out_preds->size() == 1, you will get result you want. I do not know why the online forecast needs to add this condition, and batch prediction does not require if conditions? In addition, what does base_score_ parameter mean?

这里可能是一个bug,主要在线预测实现这部分。如果把if(out_preds->size() == 1)条件注释掉 就可以得到一致的结果,主要原因是每次加载模型时base_score_参数值都不相同,并且批量预测实现中没有用到base_score_这个参数,不清楚这个为什么?另外,base_score_参数的物理意义是什么? @tqchen

diffm avatar Feb 04 '17 04:02 diffm

问题解决了吗?@earthwu

ghost avatar May 18 '18 10:05 ghost