Medial Code Documentation
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes
xgboost::gbm::GBTree Class Reference
Inheritance diagram for xgboost::gbm::GBTree:
xgboost::GradientBooster xgboost::Model xgboost::Configurable xgboost::gbm::Dart

Public Member Functions

 GBTree (LearnerModelParam const *booster_config, Context const *ctx)
 
void Configure (Args const &cfg) override
 Set the configuration of gradient boosting. User must call configure once before InitModel and Training.
 
void UpdateTreeLeaf (DMatrix const *p_fmat, HostDeviceVector< float > const &predictions, ObjFunction const *obj, std::int32_t group_idx, std::vector< HostDeviceVector< bst_node_t > > const &node_position, std::vector< std::unique_ptr< RegTree > > *p_trees)
 Optionally update the leaf value.
 
void DoBoost (DMatrix *p_fmat, HostDeviceVector< GradientPair > *in_gpair, PredictionCacheEntry *predt, ObjFunction const *obj) override
 Carry out one iteration of boosting.
 
bool UseGPU () const override
 Whether the current booster uses GPU.
 
GBTreeTrainParam const & GetTrainParam () const
 
void Load (dmlc::Stream *fi) override
 load model from stream
 
void Save (dmlc::Stream *fo) const override
 save model to stream.
 
void LoadConfig (Json const &in) override
 Load configuration from JSON object.
 
void SaveConfig (Json *p_out) const override
 Save configuration to JSON object.
 
void SaveModel (Json *p_out) const override
 saves the model config to a JSON object
 
void LoadModel (Json const &in) override
 load the model from a JSON object
 
void Slice (bst_layer_t begin, bst_layer_t end, bst_layer_t step, GradientBooster *out, bool *out_of_bound) const override
 Slice a model using boosting index.
 
std::int32_t BoostedRounds () const override
 Return number of boosted rounds.
 
bool ModelFitted () const override
 Whether the model has already been trained.
 
void PredictBatchImpl (DMatrix *p_fmat, PredictionCacheEntry *out_preds, bool is_training, bst_layer_t layer_begin, bst_layer_t layer_end) const
 
void PredictBatch (DMatrix *p_fmat, PredictionCacheEntry *out_preds, bool training, bst_layer_t layer_begin, bst_layer_t layer_end) override
 Generate predictions for given feature matrix.
 
void InplacePredict (std::shared_ptr< DMatrix > p_m, float missing, PredictionCacheEntry *out_preds, bst_layer_t layer_begin, bst_layer_t layer_end) const override
 Inplace prediction.
 
void FeatureScore (std::string const &importance_type, common::Span< int32_t const > trees, std::vector< bst_feature_t > *features, std::vector< float > *scores) const override
 
void PredictInstance (const SparsePage::Inst &inst, std::vector< bst_float > *out_preds, uint32_t layer_begin, uint32_t layer_end) override
 
void PredictLeaf (DMatrix *p_fmat, HostDeviceVector< bst_float > *out_preds, uint32_t layer_begin, uint32_t layer_end) override
 
void PredictContribution (DMatrix *p_fmat, HostDeviceVector< float > *out_contribs, bst_layer_t layer_begin, bst_layer_t layer_end, bool approximate) override
 feature contributions to individual predictions; the output will be a vector of length (nfeats + 1) * num_output_group * nsample, arranged in that order
 
void PredictInteractionContributions (DMatrix *p_fmat, HostDeviceVector< float > *out_contribs, bst_layer_t layer_begin, bst_layer_t layer_end, bool approximate) override
 
std::vector< std::string > DumpModel (const FeatureMap &fmap, bool with_stats, std::string format) const override
 dump the model in the requested format
 
- Public Member Functions inherited from xgboost::GradientBooster
 ~GradientBooster () override=default
 virtual destructor
 
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
 

Protected Member Functions

void BoostNewTrees (HostDeviceVector< GradientPair > *gpair, DMatrix *p_fmat, int bst_group, std::vector< HostDeviceVector< bst_node_t > > *out_position, std::vector< std::unique_ptr< RegTree > > *ret)
 
std::unique_ptr< Predictor > const & GetPredictor (bool is_training, HostDeviceVector< float > const *out_pred=nullptr, DMatrix *f_dmat=nullptr) const
 
virtual void CommitModel (TreesOneIter &&new_trees)
 
- Protected Member Functions inherited from xgboost::GradientBooster
 GradientBooster (Context const *ctx)
 

Protected Attributes

GBTreeModel model_
 
GBTreeTrainParam tparam_
 
tree::TrainParam tree_param_
 
bool specified_updater_ {false}
 
std::vector< std::unique_ptr< TreeUpdater > > updaters_
 
std::unique_ptr< Predictorcpu_predictor_
 
std::unique_ptr< Predictorgpu_predictor_ {nullptr}
 
common::Monitor monitor_
 
- Protected Attributes inherited from xgboost::GradientBooster
Context const * ctx_
 

Additional Inherited Members

- Static Public Member Functions inherited from xgboost::GradientBooster
static GradientBoosterCreate (const std::string &name, Context const *ctx, LearnerModelParam const *learner_model_param)
 create a gradient booster from given name
 

Member Function Documentation

◆ BoostedRounds()

std::int32_t xgboost::gbm::GBTree::BoostedRounds ( ) const
inlineoverridevirtual

Return number of boosted rounds.

Implements xgboost::GradientBooster.

◆ Configure()

void xgboost::gbm::GBTree::Configure ( Args const &  cfg)
overridevirtual

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

Parameters
cfgconfigurations on both training and model parameters.

Implements xgboost::GradientBooster.

◆ DoBoost()

void xgboost::gbm::GBTree::DoBoost ( DMatrix p_fmat,
HostDeviceVector< GradientPair > *  in_gpair,
PredictionCacheEntry predt,
ObjFunction const *  obj 
)
overridevirtual

Carry out one iteration of boosting.

Implements xgboost::GradientBooster.

◆ DumpModel()

std::vector< std::string > xgboost::gbm::GBTree::DumpModel ( const FeatureMap fmap,
bool  with_stats,
std::string  format 
) const
inlineoverridevirtual

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.

Implements xgboost::GradientBooster.

◆ FeatureScore()

void xgboost::gbm::GBTree::FeatureScore ( std::string const &  importance_type,
common::Span< int32_t const >  trees,
std::vector< bst_feature_t > *  features,
std::vector< float > *  scores 
) const
inlineoverridevirtual

◆ InplacePredict()

void xgboost::gbm::GBTree::InplacePredict ( std::shared_ptr< DMatrix ,
float  ,
PredictionCacheEntry ,
bst_layer_t  ,
bst_layer_t   
) const
overridevirtual

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 from xgboost::GradientBooster.

◆ Load()

void xgboost::gbm::GBTree::Load ( dmlc::Stream fi)
inlineoverridevirtual

load model from stream

Parameters
fiinput stream.

Implements xgboost::GradientBooster.

◆ LoadConfig()

void xgboost::gbm::GBTree::LoadConfig ( Json const &  in)
overridevirtual

Load configuration from JSON object.

Parameters
inJSON object containing the configuration

Implements xgboost::Configurable.

◆ LoadModel()

void xgboost::gbm::GBTree::LoadModel ( Json const &  in)
overridevirtual

load the model from a JSON object

Parameters
inJSON object where to load the model from

Implements xgboost::Model.

◆ ModelFitted()

bool xgboost::gbm::GBTree::ModelFitted ( ) const
inlineoverridevirtual

Whether the model has already been trained.

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

Implements xgboost::GradientBooster.

◆ PredictBatch()

void xgboost::gbm::GBTree::PredictBatch ( DMatrix dmat,
PredictionCacheEntry out_preds,
bool  training,
bst_layer_t  begin,
bst_layer_t  end 
)
overridevirtual

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.

Implements xgboost::GradientBooster.

◆ PredictContribution()

void xgboost::gbm::GBTree::PredictContribution ( DMatrix dmat,
HostDeviceVector< float > *  out_contribs,
bst_layer_t  layer_begin,
bst_layer_t  layer_end,
bool  approximate 
)
inlineoverridevirtual

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

Implements xgboost::GradientBooster.

◆ PredictInteractionContributions()

void xgboost::gbm::GBTree::PredictInteractionContributions ( DMatrix p_fmat,
HostDeviceVector< float > *  out_contribs,
bst_layer_t  layer_begin,
bst_layer_t  layer_end,
bool  approximate 
)
inlineoverridevirtual

◆ Save()

void xgboost::gbm::GBTree::Save ( dmlc::Stream fo) const
inlineoverridevirtual

save model to stream.

Parameters
fooutput stream

Implements xgboost::GradientBooster.

◆ SaveConfig()

void xgboost::gbm::GBTree::SaveConfig ( Json out) const
overridevirtual

Save configuration to JSON object.

Parameters
outpointer to output JSON object

Implements xgboost::Configurable.

◆ SaveModel()

void xgboost::gbm::GBTree::SaveModel ( Json out) const
overridevirtual

saves the model config to a JSON object

Parameters
outJSON container where to save the model to

Implements xgboost::Model.

◆ Slice()

void xgboost::gbm::GBTree::Slice ( bst_layer_t  ,
bst_layer_t  ,
bst_layer_t  ,
GradientBooster ,
bool *   
) const
overridevirtual

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 from xgboost::GradientBooster.

◆ UseGPU()

bool xgboost::gbm::GBTree::UseGPU ( ) const
inlineoverridevirtual

Whether the current booster uses GPU.

Implements xgboost::GradientBooster.


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