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.
More...
#include <predictor.h>
|
virtual | ~Predictor ()=default |
|
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. More...
|
|
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 instead of calculating from scratch. More...
|
|
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 possible. Should be called as a part of the tree boosting process to facilitate the look up of predictions at a later time. More...
|
|
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 interface if possible, batch prediction is usually more efficient than online prediction This function is NOT threadsafe, make sure you only call from one thread. More...
|
|
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 gbtree predictor. More...
|
|
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) * num_output_group * nsample, arranged in that order. More...
|
|
virtual void | PredictInteractionContributions (DMatrix *dmat, std::vector< bst_float > *out_contribs, const gbm::GBTreeModel &model, unsigned ntree_limit=0, bool approximate=false)=0 |
|
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.
◆ ~Predictor()
virtual xgboost::Predictor::~Predictor |
( |
| ) |
|
|
virtualdefault |
◆ Create()
static Predictor * xgboost::Predictor::Create |
( |
std::string |
name | ) |
|
|
static |
Creates a new Predictor*.
◆ Init()
void xgboost::Predictor::Init |
( |
const std::vector< std::pair< std::string, std::string >> & |
cfg, |
|
|
const std::vector< std::shared_ptr< DMatrix >> & |
cache |
|
) |
| |
|
virtual |
Configure and register input matrices in prediction cache.
- Parameters
-
cfg | The configuration. |
cache | Vector of DMatrix's to be used in prediction. |
◆ PredictBatch()
virtual void xgboost::Predictor::PredictBatch |
( |
DMatrix * |
dmat, |
|
|
HostDeviceVector< bst_float > * |
out_preds, |
|
|
const gbm::GBTreeModel & |
model, |
|
|
int |
tree_begin, |
|
|
unsigned |
ntree_limit = 0 |
|
) |
| |
|
pure virtual |
Generate batch predictions for a given feature matrix. May use cached predictions if available instead of calculating from scratch.
- Parameters
-
[in,out] | dmat | Feature matrix. |
[in,out] | out_preds | The output preds. |
| model | The model to predict from. |
| tree_begin | The tree begin index. |
| ntree_limit | (Optional) The ntree limit. 0 means do not limit trees. |
◆ PredictContribution()
void xgboost::Predictor::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 |
|
) |
| |
|
pure virtual |
feature contributions to individual predictions; the output will be a vector of length (nfeats + 1) * num_output_group * nsample, arranged in that order.
- Parameters
-
[in,out] | dmat | The input feature matrix. |
[in,out] | out_contribs | The output feature contribs. |
| model | Model to make predictions from. |
| ntree_limit | (Optional) The ntree limit. |
| approximate | Use fast approximate algorithm. |
| condition | Condition on the condition_feature (0=no, -1=cond off, 1=cond on). |
| condition_feature | Feature to condition on (i.e. fix) during calculations. |
◆ PredictInstance()
void xgboost::Predictor::PredictInstance |
( |
const SparsePage::Inst & |
inst, |
|
|
std::vector< bst_float > * |
out_preds, |
|
|
const gbm::GBTreeModel & |
model, |
|
|
unsigned |
ntree_limit = 0 , |
|
|
unsigned |
root_index = 0 |
|
) |
| |
|
pure virtual |
online prediction function, predict score for one instance at a time NOTE: use the batch prediction interface if possible, batch prediction is usually more efficient than online prediction This function is NOT threadsafe, make sure you only call from one thread.
- Parameters
-
| inst | The instance to predict. |
[in,out] | out_preds | The output preds. |
| model | The model to predict from |
| ntree_limit | (Optional) The ntree limit. |
| root_index | (Optional) Zero-based index of the root. |
◆ PredictInteractionContributions()
virtual void xgboost::Predictor::PredictInteractionContributions |
( |
DMatrix * |
dmat, |
|
|
std::vector< bst_float > * |
out_contribs, |
|
|
const gbm::GBTreeModel & |
model, |
|
|
unsigned |
ntree_limit = 0 , |
|
|
bool |
approximate = false |
|
) |
| |
|
pure virtual |
◆ PredictLeaf()
void xgboost::Predictor::PredictLeaf |
( |
DMatrix * |
dmat, |
|
|
std::vector< bst_float > * |
out_preds, |
|
|
const gbm::GBTreeModel & |
model, |
|
|
unsigned |
ntree_limit = 0 |
|
) |
| |
|
pure virtual |
predict the leaf index of each tree, the output will be nsample * ntree vector this is only valid in gbtree predictor.
- Parameters
-
[in,out] | dmat | The input feature matrix. |
[in,out] | out_preds | The output preds. |
| model | Model to make predictions from. |
| ntree_limit | (Optional) The ntree limit. |
◆ UpdatePredictionCache()
void xgboost::Predictor::UpdatePredictionCache |
( |
const gbm::GBTreeModel & |
model, |
|
|
std::vector< std::unique_ptr< TreeUpdater >> * |
updaters, |
|
|
int |
num_new_trees |
|
) |
| |
|
pure virtual |
Update the internal prediction cache using newly added trees. Will use the tree updater to do this if possible. Should be called as a part of the tree boosting process to facilitate the look up of predictions at a later time.
- Parameters
-
| model | The model. |
[in,out] | updaters | The updater sequence for gradient boosting. |
| num_new_trees | Number of new trees. |
◆ cache_
Map of matrices and associated cached predictions to facilitate storing and looking up predictions.
The documentation for this class was generated from the following file: