14 #include <unordered_map> 18 #include "../../src/gbm/gbtree_model.h" 19 #include "../../src/common/host_device_vector.h" 54 virtual void Init(
const std::vector<std::pair<std::string, std::string>>& cfg,
55 const std::vector<std::shared_ptr<DMatrix>>& cache);
70 const gbm::GBTreeModel& model,
int tree_begin,
71 unsigned ntree_limit = 0) = 0;
89 const gbm::GBTreeModel& model,
90 std::vector<std::unique_ptr<TreeUpdater>>* updaters,
91 int num_new_trees) = 0;
111 std::vector<bst_float>* out_preds,
112 const gbm::GBTreeModel& model,
113 unsigned ntree_limit = 0,
114 unsigned root_index = 0) = 0;
131 const gbm::GBTreeModel& model,
132 unsigned ntree_limit = 0) = 0;
153 std::vector<bst_float>* out_contribs,
154 const gbm::GBTreeModel& model,
155 unsigned ntree_limit = 0,
156 bool approximate =
false,
158 unsigned condition_feature = 0) = 0;
161 std::vector<bst_float>* out_contribs,
162 const gbm::GBTreeModel& model,
163 unsigned ntree_limit = 0,
164 bool approximate =
false) = 0;
191 std::unordered_map<DMatrix*, PredictionCacheEntry>
cache_;
198 :
public dmlc::FunctionRegEntryBase<PredictorReg,
199 std::function<Predictor*()>> {};
201 #define XGBOOST_REGISTER_PREDICTOR(UniqueId, Name) \ 202 static DMLC_ATTRIBUTE_UNUSED ::xgboost::PredictorReg& \ 203 __make_##PredictorReg##_##UniqueId##__ = \ 204 ::dmlc::Registry<::xgboost::PredictorReg>::Get()->__REGISTER__(Name) virtual void PredictContribution(DMatrix *dmat, std::vector< bst_float > *out_contribs, const gbm::GBTreeModel &model, 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) *...
virtual void PredictInstance(const SparsePage::Inst &inst, std::vector< bst_float > *out_preds, const gbm::GBTreeModel &model, 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...
virtual void PredictLeaf(DMatrix *dmat, std::vector< bst_float > *out_preds, const gbm::GBTreeModel &model, unsigned ntree_limit=0)=0
predict the leaf index of each tree, the output will be nsample * ntree vector this is only valid in ...
Performs prediction on individual training instances or batches of instances for GBTree. The predictor also manages a prediction cache associated with input matrices. If possible, it will use previously calculated predictions instead of calculating new predictions. Prediction functions all take a GBTreeModel and a DMatrix as input and output a vector of predictions. The predictor does not modify any state of the model itself.
Definition: predictor.h:40
The input data structure of xgboost.
static Predictor * Create(std::string name)
Creates a new Predictor*.
Internal data structured used by XGBoost during training. There are two ways to create a customized D...
Definition: data.h:406
Registry entry for predictor.
Definition: predictor.h:197
virtual void Init(const std::vector< std::pair< std::string, std::string >> &cfg, const std::vector< std::shared_ptr< DMatrix >> &cache)
Configure and register input matrices in prediction cache.
span class implementation, based on ISO++20 span<T>. The interface should be the same.
Definition: span.h:109
std::unordered_map< DMatrix *, PredictionCacheEntry > cache_
Map of matrices and associated cached predictions to facilitate storing and looking up predictions...
Definition: predictor.h:191
HostDeviceVector< bst_float > predictions
Definition: predictor.h:183
virtual void PredictBatch(DMatrix *dmat, HostDeviceVector< bst_float > *out_preds, const gbm::GBTreeModel &model, int tree_begin, unsigned ntree_limit=0)=0
Generate batch predictions for a given feature matrix. May use cached predictions if available instea...
namespace of xgboost
Definition: base.h:79
Contains pointer to input matrix and associated cached predictions.
Definition: predictor.h:181
defines configuration macros of xgboost.
virtual ~Predictor()=default
virtual void PredictInteractionContributions(DMatrix *dmat, std::vector< bst_float > *out_contribs, const gbm::GBTreeModel &model, unsigned ntree_limit=0, bool approximate=false)=0
virtual void UpdatePredictionCache(const gbm::GBTreeModel &model, std::vector< std::unique_ptr< TreeUpdater >> *updaters, int num_new_trees)=0
Update the internal prediction cache using newly added trees. Will use the tree updater to do this if...
std::shared_ptr< DMatrix > data
Definition: predictor.h:182