xgboost

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

interface of gradient boosting model. More...

`#include <gbm.h>`

Inheritance diagram for xgboost::GradientBooster:
Collaboration diagram for xgboost::GradientBooster:

## Public Member Functions
| ~GradientBooster () override=default
| virtual destructor More...
virtual void | Configure (const std::vector< std::pair< std::string, std::string > > &cfg)=0
| Set the configuration of gradient boosting. User must call configure once before InitModel and Training. More...
virtual void | Load (dmlc::Stream *fi)=0
| load model from stream More...
virtual void | Save (dmlc::Stream *fo) const =0
| save model to stream. More...
virtual void | Slice (int32_t layer_begin, int32_t layer_end, int32_t step, GradientBooster *out, bool *out_of_bound) const
| Slice a model using boosting index. The slice m:n indicates taking all trees that were fit during the boosting rounds m, (m+1), (m+2), ..., (n-1). More...
virtual bool | AllowLazyCheckPoint () const
| whether the model allow lazy checkpoint return true if model is only updated in DoBoost after all Allreduce calls More...
virtual void | DoBoost (DMatrix *p_fmat, HostDeviceVector< GradientPair > *in_gpair, PredictionCacheEntry *)=0
| perform update to the model(boosting) More...
virtual void | PredictBatch (DMatrix *dmat, PredictionCacheEntry *out_preds, bool training, unsigned ntree_limit=0)=0
| generate predictions for given feature matrix More...
virtual void | InplacePredict (dmlc::any const &, float, PredictionCacheEntry *, uint32_t, uint32_t) const
| Inplace prediction. More...
virtual void | PredictInstance (const SparsePage::Inst &inst, std::vector< bst_float > *out_preds, 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, 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, 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, HostDeviceVector< bst_float > *out_contribs, unsigned ntree_limit, bool approximate)=0
virtual std::vector< std::string > | DumpModel (const FeatureMap &fmap, bool with_stats, std::string format) const =0
| dump the model in the requested format More...
virtual bool | UseGPU () const =0
| Whether the current booster uses GPU. More...
Public Member Functions inherited from xgboost::Model
virtual | ~Model ()=default
virtual void | LoadModel (Json const &in)=0
| load the model from a json object More...
virtual void | SaveModel (Json *out) const =0
| saves the model config to a json object More...
Public Member Functions inherited from xgboost::Configurable
virtual | ~Configurable ()=default
virtual void | LoadConfig (Json const &in)=0
| Load configuration from JSON object. More...
virtual void | SaveConfig (Json *out) const =0
| Save configuration to JSON object. More...

## Static Public Member Functions
static GradientBooster * | Create (const std::string &name, GenericParameter const *generic_param, LearnerModelParam const *learner_model_param)
| create a gradient booster from given name More...

## Protected Attributes
GenericParameter const * | generic_param_

## Detailed Description

interface of gradient boosting model.

## Constructor & Destructor Documentation

## ◆ ~GradientBooster()

xgboost::GradientBooster::~GradientBooster | ( |  | ) |
| override default

virtual destructor

## Member Function Documentation

## ◆ AllowLazyCheckPoint()

virtual bool xgboost::GradientBooster::AllowLazyCheckPoint | ( |  | ) | const
| inline virtual

whether the model allow lazy checkpoint return true if model is only updated in DoBoost after all Allreduce calls

## ◆ Configure()

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

Set the configuration of gradient boosting. User must call configure once before InitModel and Training.

Parameters

  cfg | configurations on both training and model parameters.

## ◆ Create()

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

create a gradient booster from given name

Parameters

  name | name of gradient booster
  generic_param | Pointer to runtime parameters
  learner_model_param | pointer to global model parameters

Returns
  The created booster.

## ◆ DoBoost()

virtual void xgboost::GradientBooster::DoBoost | ( | DMatrix * | p_fmat,
|  | HostDeviceVector< GradientPair > * | in_gpair,
|  | PredictionCacheEntry * |
| ) |  |
| pure virtual

perform update to the model(boosting)

Parameters

  p_fmat | feature matrix that provide access to features
  in_gpair | address of the gradient pair statistics of the data
  prediction | The output prediction cache entry that needs to be updated. the booster may change content of gpair

## ◆ DumpModel()

virtual std::vector<std::string> xgboost::GradientBooster::DumpModel | ( | const FeatureMap & | fmap,
|  | bool | with_stats,
|  | std::string | format
| ) |  | const
| pure virtual

dump the model in the requested format

Parameters

  fmap | feature map that may help give interpretations of feature
  with_stats | extra statistics while dumping model
  format | the format to dump the model in

Returns
  a vector of dump for boosters.

## ◆ InplacePredict()

virtual void xgboost::GradientBooster::InplacePredict | ( | dmlc::any const & | ,
|  | float | ,
|  | PredictionCacheEntry * | ,
|  | uint32_t | ,
|  | uint32_t |
| ) |  | const
| inline virtual

Inplace prediction.

Parameters

  | x | A type erased data adapter.
  | missing | Missing value in the data.
  [in,out] | out_preds | The output preds.
  | layer_begin | (Optional) Begining of boosted tree layer used for prediction.
  | layer_end | (Optional) End of booster layer. 0 means do not limit trees.

## ◆ Load()

virtual void xgboost::GradientBooster::Load | ( | dmlc::Stream * | fi | ) |
| pure virtual

load model from stream

Parameters

  fi | input stream.

## ◆ PredictBatch()

virtual void xgboost::GradientBooster::PredictBatch | ( | DMatrix * | dmat,
|  | PredictionCacheEntry * | out_preds,
|  | bool | training,
|  | unsigned | ntree_limit = `0`
| ) |  |
| pure virtual

generate predictions for given feature matrix

Parameters

  dmat | feature matrix
  out_preds | output vector to hold the predictions
  training | Whether the prediction value is used for training. For dart booster drop out is performed during training.
  ntree_limit | limit the number of trees used in prediction, when it equals 0, this means we do not limit number of trees, this parameter is only valid for gbtree, but not for gblinear

## ◆ PredictContribution()

virtual void xgboost::GradientBooster::PredictContribution | ( | DMatrix * | dmat,
|  | HostDeviceVector< bst_float > * | out_contribs,
|  | 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

  dmat | feature matrix
  out_contribs | output vector to hold the contributions
  ntree_limit | limit the number of trees used in prediction, when it equals 0, this means we do not limit number of trees
  approximate | use a faster (inconsistent) approximation of SHAP values
  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::GradientBooster::PredictInstance | ( | const SparsePage::Inst & | inst,
|  | std::vector< bst_float > * | out_preds,
|  | 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 you want to predict
  out_preds | output vector to hold the predictions
  ntree_limit | limit the number of trees used in prediction

See also
  Predict

## ◆ PredictInteractionContributions()

virtual void xgboost::GradientBooster::PredictInteractionContributions | ( | DMatrix * | dmat,
|  | HostDeviceVector< bst_float > * | out_contribs,
|  | unsigned | ntree_limit,
|  | bool | approximate
| ) |  |
| pure virtual

## ◆ PredictLeaf()

virtual void xgboost::GradientBooster::PredictLeaf | ( | DMatrix * | dmat,
|  | HostDeviceVector< bst_float > * | out_preds,
|  | 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

  dmat | feature matrix
  out_preds | output vector to hold the predictions
  ntree_limit | limit the number of trees used in prediction, when it equals 0, this means we do not limit number of trees, this parameter is only valid for gbtree, but not for gblinear

## ◆ Save()

virtual void xgboost::GradientBooster::Save | ( | dmlc::Stream * | fo | ) | const
| pure virtual

save model to stream.

Parameters

  fo | output stream

## ◆ Slice()

virtual void xgboost::GradientBooster::Slice | ( | int32_t | layer_begin,
|  | int32_t | layer_end,
|  | int32_t | step,
|  | GradientBooster * | out,
|  | bool * | out_of_bound
| ) |  | const
| inline virtual

Slice a model using boosting index. The slice m:n indicates taking all trees that were fit during the boosting rounds m, (m+1), (m+2), ..., (n-1).

Parameters

  layer_begin | Begining of boosted tree layer used for prediction.
  layer_end | End of booster layer. 0 means do not limit trees.
  out | Output gradient booster

## ◆ UseGPU()

virtual bool xgboost::GradientBooster::UseGPU | ( |  | ) | const
| pure virtual

Whether the current booster uses GPU.

## Member Data Documentation

## ◆ generic_param_

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

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

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