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:

## Public Member Functions
| Predictor (GenericParameter const *generic_param)
virtual | ~Predictor ()=default
virtual void | Configure (const std::vector< std::pair< std::string, std::string >> &)
| Configure and register input matrices in prediction cache. More...
virtual void | PredictBatch (DMatrix *dmat, PredictionCacheEntry *out_preds, const gbm::GBTreeModel &model, int tree_begin, uint32_t const 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 | InplacePredict (dmlc::any const &x, const gbm::GBTreeModel &model, float missing, PredictionCacheEntry *out_preds, uint32_t tree_begin=0, uint32_t tree_end=0) const =0
| Inplace prediction. More...
virtual void | PredictInstance (const SparsePage::Inst &inst, std::vector< bst_float > *out_preds, const gbm::GBTreeModel &model, unsigned ntree_limit=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, HostDeviceVector< 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, HostDeviceVector< bst_float > *out_contribs, const gbm::GBTreeModel &model, unsigned ntree_limit=0, std::vector< bst_float > *tree_weights=nullptr, 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, HostDeviceVector< bst_float > *out_contribs, const gbm::GBTreeModel &model, unsigned ntree_limit=0, std::vector< bst_float > *tree_weights=nullptr, bool approximate=false)=0

## Static Public Member Functions
static Predictor * | Create (std::string const &name, GenericParameter const *generic_param)
| Creates a new Predictor*. More...

## Protected Attributes
GenericParameter const * | generic_param_

## 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 | ( | GenericParameter const * | generic_param | ) |
| inline explicit

## ◆ ~Predictor()

virtual xgboost::Predictor::~Predictor | ( |  | ) |
| virtual default

## Member Function Documentation

## ◆ Configure()

virtual void xgboost::Predictor::Configure | ( | const std::vector< std::pair< std::string, std::string >> & |  | ) |
| virtual

Configure and register input matrices in prediction cache.

Parameters

  cfg | The configuration.

## ◆ Create()

static Predictor* xgboost::Predictor::Create | ( | std::string const & | name,
|  | GenericParameter const * | generic_param
| ) |  |
| static

Creates a new Predictor*.

Parameters

  name | Name of the predictor.
  generic_param | Pointer to runtime parameters.

## ◆ InplacePredict()

virtual void xgboost::Predictor::InplacePredict | ( | dmlc::any const & | x,
|  | const gbm::GBTreeModel & | model,
|  | float | missing,
|  | PredictionCacheEntry * | out_preds,
|  | uint32_t | tree_begin = `0`,
|  | uint32_t | tree_end = `0`
| ) |  | const
| pure virtual

Inplace prediction.

Parameters

  | x | Type erased data adapter.
  | model | The model to predict from.
  | missing | Missing value in the data.
  [in,out] | out_preds | The output preds.
  | tree_begin | (Optional) Begining of boosted trees used for prediction.
  | tree_end | (Optional) End of booster trees. 0 means do not limit trees.

## ◆ PredictBatch()

virtual void xgboost::Predictor::PredictBatch | ( | DMatrix * | dmat,
|  | PredictionCacheEntry * | out_preds,
|  | const gbm::GBTreeModel & | model,
|  | int | tree_begin,
|  | uint32_t const | 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,
|  | HostDeviceVector< bst_float > * | out_contribs,
|  | const gbm::GBTreeModel & | model,
|  | unsigned | ntree_limit = `0`,
|  | std::vector< bst_float > * | tree_weights = `nullptr`,
|  | 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.
  | tree_weights | (Optional) Weights to multiply each tree by.
  | 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()

virtual void xgboost::Predictor::PredictInstance | ( | const SparsePage::Inst & | inst,
|  | std::vector< bst_float > * | out_preds,
|  | const gbm::GBTreeModel & | model,
|  | unsigned | ntree_limit = `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.

## ◆ PredictInteractionContributions()

virtual void xgboost::Predictor::PredictInteractionContributions | ( | DMatrix * | dmat,
|  | HostDeviceVector< bst_float > * | out_contribs,
|  | const gbm::GBTreeModel & | model,
|  | unsigned | ntree_limit = `0`,
|  | std::vector< bst_float > * | tree_weights = `nullptr`,
|  | bool | approximate = `false`
| ) |  |
| pure virtual

## ◆ PredictLeaf()

virtual void xgboost::Predictor::PredictLeaf | ( | DMatrix * | dmat,
|  | HostDeviceVector< 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.

## Member Data Documentation

## ◆ generic_param_

GenericParameter const* xgboost::Predictor::generic_param_
| protected

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

- /home/runner/work/xgboost/xgboost/include/xgboost/predictor.h