Go to the documentation of this file.
8 #ifndef XGBOOST_LEARNER_H_
9 #define XGBOOST_LEARNER_H_
28 class GradientBooster;
79 virtual void UpdateOneIter(
int iter, std::shared_ptr<DMatrix> train) = 0;
88 std::shared_ptr<DMatrix> train,
98 const std::vector<std::shared_ptr<DMatrix>>& data_sets,
99 const std::vector<std::string>& data_names) = 0;
113 virtual void Predict(std::shared_ptr<DMatrix> data,
116 unsigned ntree_limit = 0,
117 bool training =
false,
118 bool pred_leaf =
false,
119 bool pred_contribs =
false,
120 bool approx_contribs =
false,
121 bool pred_interactions =
false) = 0;
133 virtual void InplacePredict(dmlc::any
const& x, std::string
const& type,
136 uint32_t layer_begin, uint32_t layer_end) = 0;
141 virtual void LoadModel(dmlc::Stream* fi) = 0;
142 virtual void SaveModel(dmlc::Stream* fo)
const = 0;
158 virtual void SetParam(
const std::string& key,
const std::string& value) = 0;
174 virtual void SetAttr(
const std::string& key,
const std::string& value) = 0;
182 virtual bool GetAttr(
const std::string& key, std::string* out)
const = 0;
188 virtual bool DelAttr(
const std::string& key) = 0;
193 virtual std::vector<std::string>
GetAttrNames()
const = 0;
208 virtual Learner *
Slice(int32_t begin_layer, int32_t end_layer, int32_t step,
209 bool *out_of_bound) = 0;
219 std::string format) = 0;
227 static Learner*
Create(
const std::vector<std::shared_ptr<DMatrix> >& cache_data);
238 std::unique_ptr<ObjFunction>
obj_;
240 std::unique_ptr<GradientBooster>
gbm_;
247 struct LearnerModelParamLegacy;
269 #endif // XGBOOST_LEARNER_H_
std::vector< std::pair< std::string, std::string > > Args
Definition: base.h:262
virtual std::vector< std::string > DumpModel(const FeatureMap &fmap, bool with_stats, std::string format)=0
dump the model in the requested format
Interface of predictor, performs predictions for a gradient booster.
PredictionCacheEntry prediction_entry
Definition: learner.h:45
Contains pointer to input matrix and associated cached predictions.
Definition: predictor.h:35
uint32_t num_output_group
Definition: learner.h:258
Defines the abstract interface for different components in XGBoost.
virtual void Predict(std::shared_ptr< DMatrix > data, bool output_margin, HostDeviceVector< bst_float > *out_preds, unsigned ntree_limit=0, bool training=false, bool pred_leaf=false, bool pred_contribs=false, bool approx_contribs=false, bool pred_interactions=false)=0
get prediction given the model.
virtual Learner * Slice(int32_t begin_layer, int32_t end_layer, int32_t step, bool *out_of_bound)=0
Slice the model.
virtual void SetParams(Args const &args)=0
Set multiple parameters at once.
virtual void Configure()=0
Configure Learner based on set parameters.
Definition: generic_parameters.h:15
Definition: host_device_vector.h:86
std::vector< const char * > ret_vec_charp
result holder for returning string pointers
Definition: learner.h:40
virtual void BoostOneIter(int iter, std::shared_ptr< DMatrix > train, HostDeviceVector< GradientPair > *in_gpair)=0
Do customized gradient boosting with in_gpair. in_gair can be mutated after this call.
bool Initialized() const
Definition: learner.h:265
A device-and-host vector abstraction layer.
bst_float base_score
Definition: learner.h:254
virtual void SetParam(const std::string &key, const std::string &value)=0
Set parameter for booster.
defines configuration macros of xgboost.
virtual void InplacePredict(dmlc::any const &x, std::string const &type, float missing, HostDeviceVector< bst_float > **out_preds, uint32_t layer_begin, uint32_t layer_end)=0
Inplace prediction.
Feature map data structure to help visualization and model dump.
std::string ret_str
result holder for returning string
Definition: learner.h:36
std::unique_ptr< ObjFunction > obj_
objective function
Definition: learner.h:238
std::vector< bst_float > ret_vec_float
returning float vector.
Definition: learner.h:42
std::unique_ptr< GradientBooster > gbm_
The gradient booster used by the model.
Definition: learner.h:240
Definition: learner.h:252
Feature map data structure to help text model dump. TODO(tqchen) consider make it even more lightweig...
Definition: feature_map.h:22
virtual void SetAttr(const std::string &key, const std::string &value)=0
Set additional attribute to the Booster.
virtual bool GetAttr(const std::string &key, std::string *out) const =0
Get attribute from the booster. The property will be saved along the booster.
virtual void UpdateOneIter(int iter, std::shared_ptr< DMatrix > train)=0
update the model for one iteration With the specified objective function.
std::vector< std::string > ret_vec_str
result holder for returning strings
Definition: learner.h:38
static Learner * Create(const std::vector< std::shared_ptr< DMatrix > > &cache_data)
Create a new instance of learner.
bool AllowLazyCheckPoint() const
virtual uint32_t GetNumFeature()=0
Get the number of features of the booster.
virtual GenericParameter const & GetGenericParameter() const =0
std::vector< GradientPair > tmp_gpair
temp variable of gradient pairs.
Definition: learner.h:44
~Learner() override
virtual destructor
GenericParameter generic_parameters_
Training parameter.
Definition: learner.h:244
entry to to easily hold returning information
Definition: learner.h:34
virtual std::vector< std::string > GetAttrNames() const =0
Get a vector of attribute names from the booster.
virtual const std::map< std::string, std::string > & GetConfigurationArguments() const =0
Get configuration arguments currently stored by the learner.
void SaveModel(Json *out) const override=0
saves the model config to a json object
Learner class that does training and prediction. This is the user facing module of xgboost training....
Definition: learner.h:65
virtual std::string EvalOneIter(int iter, const std::vector< std::shared_ptr< DMatrix >> &data_sets, const std::vector< std::string > &data_names)=0
evaluate the model for specific iteration using the configured metrics.
std::vector< std::unique_ptr< Metric > > metrics_
The evaluation metrics used to evaluate the model.
Definition: learner.h:242
virtual XGBAPIThreadLocalEntry & GetThreadLocal() const =0
Data structure representing JSON format.
Definition: json.h:345
LearnerModelParam()=default
uint32_t num_feature
Definition: learner.h:256
virtual bool DelAttr(const std::string &key)=0
Delete an attribute from the booster.
void LoadModel(Json const &in) override=0
load the model from a json object
namespace of xgboost
Definition: base.h:110
float bst_float
float type, used for storing statistics
Definition: base.h:119