Medial Code Documentation
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
xgboost::GradientBooster Class Referenceabstract

interface of gradient boosting model. More...

#include <gbm.h>

Inheritance diagram for xgboost::GradientBooster:
xgboost::Model xgboost::Configurable xgboost::gbm::GBLinear xgboost::gbm::GBTree xgboost::gbm::Dart

Public Member Functions

 ~GradientBooster () override=default
 virtual destructor
 
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.
 
virtual void Load (dmlc::Stream *fi)=0
 load model from stream
 
virtual void Save (dmlc::Stream *fo) const =0
 save model to stream.
 
virtual void Slice (bst_layer_t, bst_layer_t, bst_layer_t, GradientBooster *, bool *) const
 Slice a model using boosting index.
 
virtual int32_t BoostedRounds () const =0
 Return number of boosted rounds.
 
virtual bool ModelFitted () const =0
 Whether the model has already been trained.
 
virtual void DoBoost (DMatrix *p_fmat, HostDeviceVector< GradientPair > *in_gpair, PredictionCacheEntry *, ObjFunction const *obj)=0
 perform update to the model(boosting)
 
virtual void PredictBatch (DMatrix *dmat, PredictionCacheEntry *out_preds, bool training, bst_layer_t begin, bst_layer_t end)=0
 Generate predictions for given feature matrix.
 
virtual void InplacePredict (std::shared_ptr< DMatrix >, float, PredictionCacheEntry *, bst_layer_t, bst_layer_t) const
 Inplace prediction.
 
virtual void PredictInstance (const SparsePage::Inst &inst, std::vector< bst_float > *out_preds, unsigned layer_begin, unsigned layer_end)=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
 
virtual void PredictLeaf (DMatrix *dmat, HostDeviceVector< bst_float > *out_preds, unsigned layer_begin, unsigned layer_end)=0
 predict the leaf index of each tree, the output will be nsample * ntree vector this is only valid in gbtree predictor
 
virtual void PredictContribution (DMatrix *dmat, HostDeviceVector< float > *out_contribs, bst_layer_t layer_begin, bst_layer_t layer_end, bool approximate=false)=0
 feature contributions to individual predictions; the output will be a vector of length (nfeats + 1) * num_output_group * nsample, arranged in that order
 
virtual void PredictInteractionContributions (DMatrix *dmat, HostDeviceVector< float > *out_contribs, bst_layer_t layer_begin, bst_layer_t layer_end, 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
 
virtual void FeatureScore (std::string const &importance_type, common::Span< int32_t const > trees, std::vector< bst_feature_t > *features, std::vector< float > *scores) const =0
 
virtual bool UseGPU () const =0
 Whether the current booster uses GPU.
 
- Public Member Functions inherited from xgboost::Model
virtual void LoadModel (Json const &in)=0
 load the model from a JSON object
 
virtual void SaveModel (Json *out) const =0
 saves the model config to a JSON object
 
- Public Member Functions inherited from xgboost::Configurable
virtual void LoadConfig (Json const &in)=0
 Load configuration from JSON object.
 
virtual void SaveConfig (Json *out) const =0
 Save configuration to JSON object.
 

Static Public Member Functions

static GradientBoosterCreate (const std::string &name, Context const *ctx, LearnerModelParam const *learner_model_param)
 create a gradient booster from given name
 

Protected Member Functions

 GradientBooster (Context const *ctx)
 

Protected Attributes

Context const * ctx_
 

Detailed Description

interface of gradient boosting model.

Member Function Documentation

◆ BoostedRounds()

virtual int32_t xgboost::GradientBooster::BoostedRounds ( ) const
pure virtual

Return number of boosted rounds.

Implemented in xgboost::gbm::GBLinear, and xgboost::gbm::GBTree.

◆ 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
cfgconfigurations on both training and model parameters.

Implemented in xgboost::gbm::GBTree, xgboost::gbm::GBLinear, and xgboost::gbm::Dart.

◆ Create()

GradientBooster * xgboost::GradientBooster::Create ( const std::string &  name,
Context const *  ctx,
LearnerModelParam const *  learner_model_param 
)
static

create a gradient booster from given name

Parameters
namename of gradient booster
generic_paramPointer to runtime parameters
learner_model_parampointer to global model parameters
Returns
The created booster.

◆ DoBoost()

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

perform update to the model(boosting)

Parameters
p_fmatfeature matrix that provide access to features
in_gpairaddress of the gradient pair statistics of the data
predictionThe output prediction cache entry that needs to be updated. the booster may change content of gpair

Implemented in xgboost::gbm::GBLinear, and xgboost::gbm::GBTree.

◆ 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
fmapfeature map that may help give interpretations of feature
with_statsextra statistics while dumping model
formatthe format to dump the model in
Returns
a vector of dump for boosters.

Implemented in xgboost::gbm::GBLinear, and xgboost::gbm::GBTree.

◆ InplacePredict()

virtual void xgboost::GradientBooster::InplacePredict ( std::shared_ptr< DMatrix ,
float  ,
PredictionCacheEntry ,
bst_layer_t  ,
bst_layer_t   
) const
inlinevirtual

Inplace prediction.

Parameters
p_fmatA proxy DMatrix that contains the data and related.
missingMissing value in the data.
[in,out]out_predsThe output preds.
begin(Optional) Beginning of boosted tree layer used for prediction.
end(Optional) End of booster layer. 0 means do not limit trees.

Reimplemented in xgboost::gbm::Dart, and xgboost::gbm::GBTree.

◆ Load()

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

load model from stream

Parameters
fiinput stream.

Implemented in xgboost::gbm::GBLinear, xgboost::gbm::Dart, and xgboost::gbm::GBTree.

◆ ModelFitted()

virtual bool xgboost::GradientBooster::ModelFitted ( ) const
pure virtual

Whether the model has already been trained.

When tree booster is chosen, then returns true when there are existing trees.

Implemented in xgboost::gbm::GBLinear, and xgboost::gbm::GBTree.

◆ PredictBatch()

virtual void xgboost::GradientBooster::PredictBatch ( DMatrix dmat,
PredictionCacheEntry out_preds,
bool  training,
bst_layer_t  begin,
bst_layer_t  end 
)
pure virtual

Generate predictions for given feature matrix.

Parameters
dmatThe feature matrix.
out_predsoutput vector to hold the predictions
trainingWhether the prediction value is used for training. For dart booster drop out is performed during training.
beginBeginning of boosted tree layer used for prediction.
endEnd of booster layer. 0 means do not limit trees.

Implemented in xgboost::gbm::GBTree, xgboost::gbm::Dart, and xgboost::gbm::GBLinear.

◆ PredictContribution()

virtual void xgboost::GradientBooster::PredictContribution ( DMatrix dmat,
HostDeviceVector< float > *  out_contribs,
bst_layer_t  layer_begin,
bst_layer_t  layer_end,
bool  approximate = false 
)
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
dmatfeature matrix
out_contribsoutput vector to hold the contributions
layer_beginBeginning of boosted tree layer used for prediction.
layer_endEnd of booster layer. 0 means do not limit trees.
approximateuse a faster (inconsistent) approximation of SHAP values

Implemented in xgboost::gbm::Dart, xgboost::gbm::GBLinear, and xgboost::gbm::GBTree.

◆ PredictInstance()

virtual void xgboost::GradientBooster::PredictInstance ( const SparsePage::Inst inst,
std::vector< bst_float > *  out_preds,
unsigned  layer_begin,
unsigned  layer_end 
)
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
instthe instance you want to predict
out_predsoutput vector to hold the predictions
layer_beginBeginning of boosted tree layer used for prediction.
layer_endEnd of booster layer. 0 means do not limit trees.
See also
Predict

Implemented in xgboost::gbm::Dart.

◆ PredictLeaf()

virtual void xgboost::GradientBooster::PredictLeaf ( DMatrix dmat,
HostDeviceVector< bst_float > *  out_preds,
unsigned  layer_begin,
unsigned  layer_end 
)
pure virtual

predict the leaf index of each tree, the output will be nsample * ntree vector this is only valid in gbtree predictor

Parameters
dmatfeature matrix
out_predsoutput vector to hold the predictions
layer_beginBeginning of boosted tree layer used for prediction.
layer_endEnd of booster layer. 0 means do not limit trees.

Implemented in xgboost::gbm::GBLinear.

◆ Save()

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

save model to stream.

Parameters
fooutput stream

Implemented in xgboost::gbm::GBLinear, xgboost::gbm::Dart, and xgboost::gbm::GBTree.

◆ Slice()

virtual void xgboost::GradientBooster::Slice ( bst_layer_t  ,
bst_layer_t  ,
bst_layer_t  ,
GradientBooster ,
bool *   
) const
inlinevirtual

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
beginBeginning of boosted tree layer used for prediction.
endEnd of booster layer. 0 means do not limit trees.
outOutput gradient booster

Reimplemented in xgboost::gbm::GBTree.

◆ UseGPU()

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

Whether the current booster uses GPU.

Implemented in xgboost::gbm::GBLinear, and xgboost::gbm::GBTree.


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