xgboost
gbm.h
Go to the documentation of this file.
1 
8 #ifndef XGBOOST_GBM_H_
9 #define XGBOOST_GBM_H_
10 
11 #include <dmlc/registry.h>
12 #include <vector>
13 #include <utility>
14 #include <string>
15 #include <functional>
16 #include <memory>
17 #include "./base.h"
18 #include "./data.h"
19 #include "./objective.h"
20 #include "./feature_map.h"
21 #include "../../src/common/host_device_vector.h"
22 
23 namespace xgboost {
28  public:
30  virtual ~GradientBooster() = default;
37  template<typename PairIter>
38  inline void Configure(PairIter begin, PairIter end);
45  virtual void Configure(const std::vector<std::pair<std::string, std::string> >& cfg) = 0;
50  virtual void Load(dmlc::Stream* fi) = 0;
55  virtual void Save(dmlc::Stream* fo) const = 0;
61  virtual bool AllowLazyCheckPoint() const {
62  return false;
63  }
71  virtual void DoBoost(DMatrix* p_fmat,
73  ObjFunction* obj = nullptr) = 0;
74 
82  virtual void PredictBatch(DMatrix* dmat,
83  HostDeviceVector<bst_float>* out_preds,
84  unsigned ntree_limit = 0) = 0;
97  virtual void PredictInstance(const SparsePage::Inst& inst,
98  std::vector<bst_float>* out_preds,
99  unsigned ntree_limit = 0,
100  unsigned root_index = 0) = 0;
109  virtual void PredictLeaf(DMatrix* dmat,
110  std::vector<bst_float>* out_preds,
111  unsigned ntree_limit = 0) = 0;
112 
124  virtual void PredictContribution(DMatrix* dmat,
125  std::vector<bst_float>* out_contribs,
126  unsigned ntree_limit = 0, bool approximate = false,
127  int condition = 0, unsigned condition_feature = 0) = 0;
128 
129  virtual void PredictInteractionContributions(DMatrix* dmat,
130  std::vector<bst_float>* out_contribs,
131  unsigned ntree_limit, bool approximate) = 0;
132 
140  virtual std::vector<std::string> DumpModel(const FeatureMap& fmap,
141  bool with_stats,
142  std::string format) const = 0;
150  static GradientBooster* Create(
151  const std::string& name,
152  const std::vector<std::shared_ptr<DMatrix> >& cache_mats,
153  bst_float base_margin);
154 };
155 
156 // implementing configure.
157 template<typename PairIter>
158 inline void GradientBooster::Configure(PairIter begin, PairIter end) {
159  std::vector<std::pair<std::string, std::string> > vec(begin, end);
160  this->Configure(vec);
161 }
162 
167  : public dmlc::FunctionRegEntryBase<
168  GradientBoosterReg,
169  std::function<GradientBooster* (const std::vector<std::shared_ptr<DMatrix> > &cached_mats,
170  bst_float base_margin)> > {
171 };
172 
185 #define XGBOOST_REGISTER_GBM(UniqueId, Name) \
186  static DMLC_ATTRIBUTE_UNUSED ::xgboost::GradientBoosterReg & \
187  __make_ ## GradientBoosterReg ## _ ## UniqueId ## __ = \
188  ::dmlc::Registry< ::xgboost::GradientBoosterReg>::Get()->__REGISTER__(Name)
189 
190 } // namespace xgboost
191 #endif // XGBOOST_GBM_H_
virtual void PredictInstance(const SparsePage::Inst &inst, std::vector< bst_float > *out_preds, unsigned ntree_limit=0, unsigned root_index=0)=0
online prediction function, predict score for one instance at a time NOTE: use the batch prediction i...
float bst_float
float type, used for storing statistics
Definition: base.h:89
void Configure(PairIter begin, PairIter end)
set configuration from pair iterators.
Definition: gbm.h:158
virtual std::vector< std::string > DumpModel(const FeatureMap &fmap, bool with_stats, std::string format) const =0
dump the model in the requested format
virtual ~GradientBooster()=default
virtual destructor
virtual void PredictContribution(DMatrix *dmat, std::vector< bst_float > *out_contribs, unsigned ntree_limit=0, bool approximate=false, int condition=0, unsigned condition_feature=0)=0
feature contributions to individual predictions; the output will be a vector of length (nfeats + 1) *...
Definition: host_device_vector.h:200
virtual void PredictInteractionContributions(DMatrix *dmat, std::vector< bst_float > *out_contribs, unsigned ntree_limit, bool approximate)=0
The input data structure of xgboost.
static GradientBooster * Create(const std::string &name, const std::vector< std::shared_ptr< DMatrix > > &cache_mats, bst_float base_margin)
create a gradient booster from given name
Internal data structured used by XGBoost during training. There are two ways to create a customized D...
Definition: data.h:406
Feature map data structure to help text model dump. TODO(tqchen) consider make it even more lightweig...
Definition: feature_map.h:20
span class implementation, based on ISO++20 span<T>. The interface should be the same.
Definition: span.h:109
Registry entry for tree updater.
Definition: gbm.h:166
virtual bool AllowLazyCheckPoint() const
whether the model allow lazy checkpoint return true if model is only updated in DoBoost after all All...
Definition: gbm.h:61
interface of objective function used by xgboost.
virtual void PredictLeaf(DMatrix *dmat, std::vector< bst_float > *out_preds, unsigned ntree_limit=0)=0
predict the leaf index of each tree, the output will be nsample * ntree vector this is only valid in ...
virtual void Load(dmlc::Stream *fi)=0
load model from stream
interface of objective function
Definition: objective.h:23
Feature map data structure to help visualization and model dump.
namespace of xgboost
Definition: base.h:79
defines configuration macros of xgboost.
virtual void Save(dmlc::Stream *fo) const =0
save model to stream.
virtual void DoBoost(DMatrix *p_fmat, HostDeviceVector< GradientPair > *in_gpair, ObjFunction *obj=nullptr)=0
perform update to the model(boosting)
virtual void PredictBatch(DMatrix *dmat, HostDeviceVector< bst_float > *out_preds, unsigned ntree_limit=0)=0
generate predictions for given feature matrix
interface of gradient boosting model.
Definition: gbm.h:27