xgboost
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
xgboost::Predictor Class Referenceabstract

Performs prediction on individual training instances or batches of instances for GBTree. 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>

Collaboration diagram for xgboost::Predictor:
Collaboration graph

Public Member Functions

 Predictor (Context const *ctx)
 
virtual ~Predictor ()=default
 
virtual void Configure (Args const &)
 Configure and register input matrices in prediction cache. More...
 
virtual void InitOutPredictions (const MetaInfo &info, HostDeviceVector< float > *out_predt, const gbm::GBTreeModel &model) const
 Initialize output prediction. More...
 
virtual void PredictBatch (DMatrix *dmat, PredictionCacheEntry *out_preds, gbm::GBTreeModel const &model, bst_tree_t tree_begin, bst_tree_t tree_end=0) const =0
 Generate batch predictions for a given feature matrix. May use cached predictions if available instead of calculating from scratch. More...
 
virtual bool InplacePredict (std::shared_ptr< DMatrix > p_fmat, const gbm::GBTreeModel &model, float missing, PredictionCacheEntry *out_preds, bst_tree_t tree_begin=0, bst_tree_t tree_end=0) const =0
 Inplace prediction. More...
 
virtual void PredictLeaf (DMatrix *dmat, HostDeviceVector< float > *out_preds, gbm::GBTreeModel const &model, bst_tree_t tree_end=0) const =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, HostDeviceVector< float > *out_contribs, gbm::GBTreeModel const &model, bst_tree_t tree_end=0, std::vector< float > const *tree_weights=nullptr, bool approximate=false, int condition=0, unsigned condition_feature=0) const =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, HostDeviceVector< float > *out_contribs, gbm::GBTreeModel const &model, bst_tree_t tree_end=0, std::vector< float > const *tree_weights=nullptr, bool approximate=false) const =0
 

Static Public Member Functions

static PredictorCreate (std::string const &name, Context const *ctx)
 Creates a new Predictor*. More...
 

Protected Attributes

Context const * ctx_
 

Detailed Description

Performs prediction on individual training instances or batches of instances for GBTree. 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.

Constructor & Destructor Documentation

◆ Predictor()

xgboost::Predictor::Predictor ( Context const *  ctx)
inlineexplicit

◆ ~Predictor()

virtual xgboost::Predictor::~Predictor ( )
virtualdefault

Member Function Documentation

◆ Configure()

virtual void xgboost::Predictor::Configure ( Args const &  )
virtual

Configure and register input matrices in prediction cache.

Parameters
cfgThe configuration.

◆ Create()

static Predictor* xgboost::Predictor::Create ( std::string const &  name,
Context const *  ctx 
)
static

Creates a new Predictor*.

Parameters
nameName of the predictor.
ctxPointer to runtime parameters.

◆ InitOutPredictions()

virtual void xgboost::Predictor::InitOutPredictions ( const MetaInfo info,
HostDeviceVector< float > *  out_predt,
const gbm::GBTreeModel &  model 
) const
virtual

Initialize output prediction.

Parameters
infoMeta info for the DMatrix object used for prediction.
out_predtPrediction vector to be initialized.
modelTree model used for prediction.

◆ InplacePredict()

virtual bool xgboost::Predictor::InplacePredict ( std::shared_ptr< DMatrix p_fmat,
const gbm::GBTreeModel &  model,
float  missing,
PredictionCacheEntry out_preds,
bst_tree_t  tree_begin = 0,
bst_tree_t  tree_end = 0 
) const
pure virtual

Inplace prediction.

Parameters
p_fmatA proxy DMatrix that contains the data and related meta info.
modelThe model to predict from.
missingMissing value in the data.
[in,out]out_predsThe output preds.
tree_begin(Optional) Beginning of boosted trees used for prediction.
tree_end(Optional) End of booster trees. 0 means do not limit trees.
Returns
True if the data can be handled by current predictor, false otherwise.

◆ PredictBatch()

virtual void xgboost::Predictor::PredictBatch ( DMatrix dmat,
PredictionCacheEntry out_preds,
gbm::GBTreeModel const &  model,
bst_tree_t  tree_begin,
bst_tree_t  tree_end = 0 
) const
pure virtual

Generate batch predictions for a given feature matrix. May use cached predictions if available instead of calculating from scratch.

Parameters
[in,out]dmatFeature matrix.
[in,out]out_predsThe output preds.
modelThe model to predict from.
tree_beginThe tree begin index.
tree_endThe tree end index.

◆ PredictContribution()

virtual void xgboost::Predictor::PredictContribution ( DMatrix dmat,
HostDeviceVector< float > *  out_contribs,
gbm::GBTreeModel const &  model,
bst_tree_t  tree_end = 0,
std::vector< float > const *  tree_weights = nullptr,
bool  approximate = false,
int  condition = 0,
unsigned  condition_feature = 0 
) const
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]dmatThe input feature matrix.
[in,out]out_contribsThe output feature contribs.
modelModel to make predictions from.
tree_endThe tree end index.
tree_weights(Optional) Weights to multiply each tree by.
approximateUse fast approximate algorithm.
conditionCondition on the condition_feature (0=no, -1=cond off, 1=cond on).
condition_featureFeature to condition on (i.e. fix) during calculations.

◆ PredictInteractionContributions()

virtual void xgboost::Predictor::PredictInteractionContributions ( DMatrix dmat,
HostDeviceVector< float > *  out_contribs,
gbm::GBTreeModel const &  model,
bst_tree_t  tree_end = 0,
std::vector< float > const *  tree_weights = nullptr,
bool  approximate = false 
) const
pure virtual

◆ PredictLeaf()

virtual void xgboost::Predictor::PredictLeaf ( DMatrix dmat,
HostDeviceVector< float > *  out_preds,
gbm::GBTreeModel const &  model,
bst_tree_t  tree_end = 0 
) const
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]dmatThe input feature matrix.
[in,out]out_predsThe output preds.
modelModel to make predictions from.
tree_end(Optional) The tree end index.

Member Data Documentation

◆ ctx_

Context const* xgboost::Predictor::ctx_
protected

The documentation for this class was generated from the following file: