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

interface of gradient boosting model. More...

#include <gbm.h>

Collaboration diagram for xgboost::GradientBooster:
Collaboration graph

Public Member Functions

virtual ~GradientBooster ()=default
 virtual destructor More...
 
template<typename PairIter >
void Configure (PairIter begin, PairIter end)
 set configuration from pair iterators. 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 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, ObjFunction *obj=nullptr)=0
 perform update to the model(boosting) More...
 
virtual void PredictBatch (DMatrix *dmat, HostDeviceVector< bst_float > *out_preds, unsigned ntree_limit=0)=0
 generate predictions for given feature matrix More...
 
virtual void PredictInstance (const SparsePage::Inst &inst, std::vector< bst_float > *out_preds, unsigned ntree_limit=0, unsigned root_index=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, std::vector< 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, std::vector< 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, std::vector< 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...
 

Static Public Member Functions

static GradientBoosterCreate (const std::string &name, const std::vector< std::shared_ptr< DMatrix > > &cache_mats, bst_float base_margin)
 create a gradient booster from given name More...
 

Detailed Description

interface of gradient boosting model.

Constructor & Destructor Documentation

◆ ~GradientBooster()

virtual xgboost::GradientBooster::~GradientBooster ( )
virtualdefault

virtual destructor

Member Function Documentation

◆ AllowLazyCheckPoint()

virtual bool xgboost::GradientBooster::AllowLazyCheckPoint ( ) const
inlinevirtual

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

◆ Configure() [1/2]

template<typename PairIter >
void xgboost::GradientBooster::Configure ( PairIter  begin,
PairIter  end 
)
inline

set configuration from pair iterators.

Parameters
beginThe beginning iterator.
endThe end iterator.
Template Parameters
PairIteriterator<std::pair<std::string, std::string> >

◆ Configure() [2/2]

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.

◆ Create()

static GradientBooster* xgboost::GradientBooster::Create ( const std::string &  name,
const std::vector< std::shared_ptr< DMatrix > > &  cache_mats,
bst_float  base_margin 
)
static

create a gradient booster from given name

Parameters
namename of gradient booster
cache_matsThe cache data matrix of the Booster.
base_marginThe base margin of prediction.
Returns
The created booster.

◆ DoBoost()

virtual void xgboost::GradientBooster::DoBoost ( DMatrix p_fmat,
HostDeviceVector< GradientPair > *  in_gpair,
ObjFunction obj = nullptr 
)
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
objThe objective function, optional, can be nullptr when use customized version 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
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.

◆ Load()

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

load model from stream

Parameters
fiinput stream.

◆ PredictBatch()

virtual void xgboost::GradientBooster::PredictBatch ( DMatrix dmat,
HostDeviceVector< bst_float > *  out_preds,
unsigned  ntree_limit = 0 
)
pure virtual

generate predictions for given feature matrix

Parameters
dmatfeature matrix
out_predsoutput vector to hold the predictions
ntree_limitlimit 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,
std::vector< 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
dmatfeature matrix
out_contribsoutput vector to hold the contributions
ntree_limitlimit the number of trees used in prediction, when it equals 0, this means we do not limit number of trees
approximateuse a faster (inconsistent) approximation of SHAP values
conditioncondition on the condition_feature (0=no, -1=cond off, 1=cond on).
condition_featurefeature 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,
unsigned  root_index = 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
instthe instance you want to predict
out_predsoutput vector to hold the predictions
ntree_limitlimit the number of trees used in prediction
root_indexthe root index
See also
Predict

◆ PredictInteractionContributions()

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

◆ PredictLeaf()

virtual void xgboost::GradientBooster::PredictLeaf ( DMatrix dmat,
std::vector< 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
dmatfeature matrix
out_predsoutput vector to hold the predictions
ntree_limitlimit 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
fooutput stream

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