Medial Code Documentation
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions
xgboost::LearnerImpl Class Reference

learner that performs gradient boosting for a specific objective function. It does training and prediction. More...

Inheritance diagram for xgboost::LearnerImpl:
xgboost::LearnerIO xgboost::LearnerConfiguration xgboost::Learner xgboost::Model xgboost::Configurable dmlc::Serializable

Public Member Functions

 LearnerImpl (std::vector< std::shared_ptr< DMatrix > > cache)
 
std::vector< std::string > DumpModel (const FeatureMap &fmap, bool with_stats, std::string format) override
 dump the model in the requested format
 
LearnerSlice (bst_layer_t begin, bst_layer_t end, bst_layer_t step, bool *out_of_bound) override
 Slice the model.
 
void UpdateOneIter (int iter, std::shared_ptr< DMatrix > train) override
 update the model for one iteration With the specified objective function.
 
void BoostOneIter (int iter, std::shared_ptr< DMatrix > train, HostDeviceVector< GradientPair > *in_gpair) override
 Do customized gradient boosting with in_gpair. in_gair can be mutated after this call.
 
std::string EvalOneIter (int iter, const std::vector< std::shared_ptr< DMatrix > > &data_sets, const std::vector< std::string > &data_names) override
 evaluate the model for specific iteration using the configured metrics.
 
void Predict (std::shared_ptr< DMatrix > data, bool output_margin, HostDeviceVector< bst_float > *out_preds, bst_layer_t layer_begin, bst_layer_t layer_end, bool training, bool pred_leaf, bool pred_contribs, bool approx_contribs, bool pred_interactions) override
 get prediction given the model.
 
int32_t BoostedRounds () const override
 
uint32_t Groups () const override
 Get the number of output groups from the model.
 
XGBAPIThreadLocalEntryGetThreadLocal () const override
 
void InplacePredict (std::shared_ptr< DMatrix > p_m, PredictionType type, float missing, HostDeviceVector< float > **out_preds, bst_layer_t iteration_begin, bst_layer_t iteration_end) override
 Inplace prediction.
 
void CalcFeatureScore (std::string const &importance_type, common::Span< int32_t const > trees, std::vector< bst_feature_t > *features, std::vector< float > *scores) override
 Calculate feature score. See doc in C API for outputs.
 
const std::map< std::string, std::string > & GetConfigurationArguments () const override
 Get configuration arguments currently stored by the learner.
 
- Public Member Functions inherited from xgboost::LearnerIO
 LearnerIO (std::vector< std::shared_ptr< DMatrix > > cache)
 
void LoadModel (Json const &in) override
 load the model from a JSON object
 
void SaveModel (Json *p_out) const override
 saves the model config to a JSON object
 
void LoadModel (dmlc::Stream *fi) override
 
void SaveModel (dmlc::Stream *fo) const override
 
void Save (dmlc::Stream *fo) const override
 saves the model to a stream
 
void Load (dmlc::Stream *fi) override
 load the model from a stream
 
- Public Member Functions inherited from xgboost::LearnerConfiguration
 LearnerConfiguration (std::vector< std::shared_ptr< DMatrix > > cache)
 
void Configure () override
 Configure Learner based on set parameters.
 
void CheckModelInitialized () const
 
void LoadConfig (Json const &in) override
 Load configuration from JSON object.
 
void SaveConfig (Json *p_out) const override
 Save configuration to JSON object.
 
void SetParam (const std::string &key, const std::string &value) override
 Set parameter for booster.
 
void SetParams (std::vector< std::pair< std::string, std::string > > const &args) override
 Set multiple parameters at once.
 
uint32_t GetNumFeature () const override
 Get the number of features of the booster.
 
void SetAttr (const std::string &key, const std::string &value) override
 Set additional attribute to the Booster.
 
bool GetAttr (const std::string &key, std::string *out) const override
 Get attribute from the booster. The property will be saved along the booster.
 
bool DelAttr (const std::string &key) override
 Delete an attribute from the booster.
 
void SetFeatureNames (std::vector< std::string > const &fn) override
 Set the feature names for current booster.
 
void GetFeatureNames (std::vector< std::string > *fn) const override
 Get the feature names for current booster.
 
void SetFeatureTypes (std::vector< std::string > const &ft) override
 Set the feature types for current booster.
 
void GetFeatureTypes (std::vector< std::string > *p_ft) const override
 Get the feature types for current booster.
 
std::vector< std::string > GetAttrNames () const override
 Get a vector of attribute names from the booster.
 
Context const * Ctx () const override
 Return the context object of this Booster.
 
- Public Member Functions inherited from xgboost::Learner
 ~Learner () override
 virtual destructor
 
- Public Member Functions inherited from dmlc::Serializable
virtual ~Serializable ()
 virtual destructor
 

Protected Member Functions

void PredictRaw (DMatrix *data, PredictionCacheEntry *out_preds, bool training, unsigned layer_begin, unsigned layer_end) const
 get un-transformed prediction
 
void ValidateDMatrix (DMatrix *p_fmat, bool is_training) const
 
- Protected Member Functions inherited from xgboost::LearnerConfiguration
void ConfigureModelParamWithoutBaseScore ()
 
void InitBaseScore (DMatrix const *p_fmat)
 Calculate the base_score based on input data.
 

Additional Inherited Members

- Static Public Member Functions inherited from xgboost::Learner
static LearnerCreate (const std::vector< std::shared_ptr< DMatrix > > &cache_data)
 Create a new instance of learner.
 
- Protected Attributes inherited from xgboost::LearnerConfiguration
std::atomic< bool > need_configuration_
 
std::map< std::string, std::string > cfg_
 
std::map< std::string, std::string > attributes_
 
std::vector< std::string > feature_names_
 
std::vector< std::string > feature_types_
 
common::Monitor monitor_
 
LearnerModelParamLegacy mparam_
 
LearnerModelParam learner_model_param_
 
LearnerTrainParam tparam_
 
PredictionContainer prediction_container_
 
std::vector< std::string > metric_names_
 
- Protected Attributes inherited from xgboost::Learner
std::unique_ptr< ObjFunctionobj_
 objective function
 
std::unique_ptr< GradientBoostergbm_
 The gradient booster used by the model.
 
std::vector< std::unique_ptr< Metric > > metrics_
 The evaluation metrics used to evaluate the model.
 
Context ctx_
 Training parameter.
 
- Static Protected Attributes inherited from xgboost::LearnerConfiguration
static std::string const kEvalMetric {"eval_metric"}
 

Detailed Description

learner that performs gradient boosting for a specific objective function. It does training and prediction.

Member Function Documentation

◆ BoostedRounds()

int32_t xgboost::LearnerImpl::BoostedRounds ( ) const
inlineoverridevirtual

Implements xgboost::Learner.

◆ BoostOneIter()

void xgboost::LearnerImpl::BoostOneIter ( int  iter,
std::shared_ptr< DMatrix train,
HostDeviceVector< GradientPair > *  in_gpair 
)
inlineoverridevirtual

Do customized gradient boosting with in_gpair. in_gair can be mutated after this call.

Parameters
itercurrent iteration number
trainreference to the data matrix.
in_gpairThe input gradient statistics.

Implements xgboost::Learner.

◆ CalcFeatureScore()

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

Calculate feature score. See doc in C API for outputs.

Implements xgboost::Learner.

◆ DumpModel()

std::vector< std::string > xgboost::LearnerImpl::DumpModel ( const FeatureMap fmap,
bool  with_stats,
std::string  format 
)
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::Learner.

◆ EvalOneIter()

std::string xgboost::LearnerImpl::EvalOneIter ( int  iter,
const std::vector< std::shared_ptr< DMatrix > > &  data_sets,
const std::vector< std::string > &  data_names 
)
inlineoverridevirtual

evaluate the model for specific iteration using the configured metrics.

Parameters
iteriteration number
data_setsdatasets to be evaluated.
data_namesname of each dataset
Returns
a string corresponding to the evaluation result

Implements xgboost::Learner.

◆ GetConfigurationArguments()

const std::map< std::string, std::string > & xgboost::LearnerImpl::GetConfigurationArguments ( ) const
inlineoverridevirtual

Get configuration arguments currently stored by the learner.

Returns
Key-value pairs representing configuration arguments

Reimplemented from xgboost::LearnerConfiguration.

◆ GetThreadLocal()

XGBAPIThreadLocalEntry & xgboost::LearnerImpl::GetThreadLocal ( ) const
inlineoverridevirtual

Implements xgboost::Learner.

◆ Groups()

uint32_t xgboost::LearnerImpl::Groups ( ) const
inlineoverridevirtual

Get the number of output groups from the model.

Implements xgboost::Learner.

◆ InplacePredict()

void xgboost::LearnerImpl::InplacePredict ( std::shared_ptr< DMatrix p_m,
PredictionType  type,
float  missing,
HostDeviceVector< float > **  out_preds,
bst_layer_t  layer_begin,
bst_layer_t  layer_end 
)
inlineoverridevirtual

Inplace prediction.

Parameters
p_fmatA proxy DMatrix that contains the data and related meta info.
typePrediction type.
missingMissing value in the data.
[in,out]out_predsPointer to output prediction vector.
layer_beginBeginning of boosted tree layer used for prediction.
layer_endEnd of booster layer. 0 means do not limit trees.

Implements xgboost::Learner.

◆ Predict()

void xgboost::LearnerImpl::Predict ( std::shared_ptr< DMatrix data,
bool  output_margin,
HostDeviceVector< bst_float > *  out_preds,
bst_layer_t  layer_begin,
bst_layer_t  layer_end,
bool  training,
bool  pred_leaf,
bool  pred_contribs,
bool  approx_contribs,
bool  pred_interactions 
)
inlineoverridevirtual

get prediction given the model.

Parameters
datainput data
output_marginwhether to only predict margin value instead of transformed prediction
out_predsoutput vector that stores the prediction
layer_beginBeginning of boosted tree layer used for prediction.
layer_endEnd of booster layer. 0 means do not limit trees.
trainingWhether the prediction result is used for training
pred_leafwhether to only predict the leaf index of each tree in a boosted tree predictor
pred_contribswhether to only predict the feature contributions
approx_contribswhether to approximate the feature contributions for speed
pred_interactionswhether to compute the feature pair contributions

Implements xgboost::Learner.

◆ PredictRaw()

void xgboost::LearnerImpl::PredictRaw ( DMatrix data,
PredictionCacheEntry out_preds,
bool  training,
unsigned  layer_begin,
unsigned  layer_end 
) const
inlineprotected

get un-transformed prediction

Parameters
datatraining data matrix
out_predsoutput vector that stores the prediction
ntree_limitlimit number of trees used for boosted tree predictor, when it equals 0, this means we are using all the trees
trainingallow dropout when the DART booster is being used

◆ Slice()

Learner * xgboost::LearnerImpl::Slice ( bst_layer_t  begin,
bst_layer_t  end,
bst_layer_t  step,
bool *  out_of_bound 
)
inlineoverridevirtual

Slice the model.

See InplacePredict for layer parameters.

Parameters
stepstep size between slice.
out_of_boundReturn true if end layer is out of bound.
Returns
a sliced model.

Implements xgboost::Learner.

◆ UpdateOneIter()

void xgboost::LearnerImpl::UpdateOneIter ( int  iter,
std::shared_ptr< DMatrix train 
)
inlineoverridevirtual

update the model for one iteration With the specified objective function.

Parameters
itercurrent iteration number
trainreference to the data matrix.

Implements xgboost::Learner.


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