xgboost
公共成员函数 | 静态公共成员函数 | 保护属性 | 所有成员列表
xgboost::Learner 类参考抽象

Learner 类,用于执行训练和预测。这是xgboost训练的用户界面模块。Load/Save 函数对应于 Python/R 中使用的模型。更多...

#include <learner.h>

xgboost::Learner 的继承图
Inheritance graph
xgboost::Learner 的协作图
Collaboration graph

公共成员函数

 ~Learner () override
 虚析构函数 更多...
 
virtual void 配置 ()=0
 根据设置的参数配置Learner更多...
 
virtual void UpdateOneIter (std::int32_t iter, std::shared_ptr< DMatrix > train)=0
 使用指定的目标函数更新模型一次迭代。 更多...
 
virtual void BoostOneIter (std::int32_t iter, std::shared_ptr< DMatrix > train, linalg::Matrix< GradientPair > *in_gpair)=0
 使用 in_gpair 进行自定义梯度提升。 更多...
 
virtual std::string EvalOneIter (int iter, const std::vector< std::shared_ptr< DMatrix >> &data_sets, const std::vector< std::string > &data_names)=0
 使用配置的指标评估特定迭代的模型。 更多...
 
virtual 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=false, bool pred_leaf=false, bool pred_contribs=false, bool approx_contribs=false, bool pred_interactions=false)=0
 给定模型进行预测。 更多...
 
virtual void 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)=0
 原地预测。 更多...
 
virtual void CalcFeatureScore (std::string const &importance_type, common::Span< int32_t const > trees, std::vector< bst_feature_t > *features, std::vector< float > *scores)=0
 计算特征分数。参见 C API 文档了解输出。 更多...
 
virtual int32_t BoostedRounds () const =0
 
virtual std::uint32_t Groups () const =0
 获取模型的输出组数量。 更多...
 
void LoadModel (Json const &in) override=0
 从 JSON 对象加载模型 更多...
 
void SaveModel (Json *out) const override=0
 将模型配置保存到 JSON 对象 更多...
 
virtual void SetParams (Args const &args)=0
 一次性设置多个参数。 更多...
 
virtual void SetParam (const std::string &key, const std::string &value)=0
 设置 booster 参数。 更多...
 
virtual bst_feature_t GetNumFeature () const =0
 获取 booster 的特征数量。 更多...
 
virtual void SetAttr (const std::string &key, const std::string &value)=0
 为 Booster 设置附加属性。 更多...
 
virtual bool GetAttr (const std::string &key, std::string *out) const =0
 从 booster 获取属性。该属性将与 booster 一起保存。 更多...
 
virtual bool DelAttr (const std::string &key)=0
 从 booster 中删除属性。 更多...
 
virtual std::vector< std::string > GetAttrNames () const =0
 从 booster 获取属性名称向量。 更多...
 
virtual void SetFeatureNames (std::vector< std::string > const &fn)=0
 为当前 booster 设置特征名称。 更多...
 
virtual void GetFeatureNames (std::vector< std::string > *fn) const =0
 获取当前 booster 的特征名称。 更多...
 
virtual void SetFeatureTypes (std::vector< std::string > const &ft)=0
 为当前 booster 设置特征类型。 更多...
 
virtual void GetFeatureTypes (std::vector< std::string > *ft) const =0
 获取当前 booster 的特征类型。 更多...
 
virtual CatContainer const * Cats () const =0
 获取类别。 更多...
 
virtual LearnerSlice (bst_layer_t begin, bst_layer_t end, bst_layer_t step, bool *out_of_bound)=0
 切片模型。 更多...
 
virtual std::vector< std::string > DumpModel (const FeatureMap &fmap, bool with_stats, std::string format)=0
 以请求的格式转储模型 更多...
 
virtual XGBAPIThreadLocalEntry & GetThreadLocal () const =0
 
virtual void 重置 ()=0
 重置 booster 对象以释放用于训练的数据缓存。 更多...
 
virtual Context const * Ctx () const =0
 返回此 Booster 的上下文对象。 更多...
 
virtual const std::map< std::string, std::string > & GetConfigurationArguments () const =0
 获取学习器当前存储的配置参数。 更多...
 
- 从 xgboost::Model 继承的公共成员函数
virtual ~Model ()=default
 
- 从 xgboost::Configurable 继承的公共成员函数
virtual ~Configurable ()=default
 
virtual void LoadConfig (Json const &in)=0
 从 JSON 对象加载配置。 更多...
 
virtual void SaveConfig (Json *out) const =0
 将配置保存到 JSON 对象。 更多...
 

静态公共成员函数

static LearnerCreate (const std::vector< std::shared_ptr< DMatrix > > &cache_data)
 创建 Learner 的新实例。 更多...
 

保护属性

std::unique_ptr< ObjFunctionobj_
 目标函数 更多...
 
std::unique_ptr< GradientBoostergbm_
 模型使用的梯度助推器。 更多...
 
std::vector< std::unique_ptr< Metric > > metrics_
 用于评估模型的评估指标。 更多...
 
Context ctx_
 训练参数。 更多...
 

详细描述

Learner 类,用于训练和预测。这是 xgboost 训练面向用户的模块。加载/保存函数对应于 python/R 中使用的模型。

std::unique_ptr<Learner> learner(new Learner::Create(cache_mats));
learner.Configure(configs);
for (int iter = 0; iter < max_iter; ++iter) {
learner->UpdateOneIter(iter, train_mat);
LOG(INFO) << learner->EvalOneIter(iter, data_sets, data_names);
}
static Learner * Create(const std::vector< std::shared_ptr< DMatrix > > &cache_data)
创建 Learner 的新实例。

构造函数和析构函数文档

◆ ~Learner()

xgboost::Learner::~Learner ( )
override

虚析构函数

成员函数文档

◆ BoostedRounds()

virtual int32_t xgboost::Learner::BoostedRounds ( ) const
纯虚函数

◆ BoostOneIter()

virtual void xgboost::Learner::BoostOneIter ( std::int32_t  iter,
std::shared_ptr< DMatrix 训练,
linalg::Matrix< GradientPair > *  in_gpair 
)
纯虚函数

使用 in_gpair 进行自定义梯度提升。

注意
此调用后 in_gpair 可能会被修改。
参数
iter当前迭代次数
训练数据矩阵的引用。
in_gpair输入梯度统计信息。

◆ CalcFeatureScore()

virtual void xgboost::Learner::CalcFeatureScore ( std::string const &  重要性类型,
common::Span< int32_t const >  ,
std::vector< bst_feature_t > *  features,
std::vector< float > *  分数 
)
纯虚函数

计算特征分数。参见 C API 文档了解输出。

◆ Cats()

virtual CatContainer const* xgboost::Learner::Cats ( ) const
纯虚函数

类别的 Getter。

◆ Configure()

virtual void xgboost::Learner::Configure ( )
纯虚函数

根据设置的参数配置Learner

◆ Create()

static Learner* xgboost::Learner::Create ( const std::vector< std::shared_ptr< DMatrix > > &  cache_data)
static

创建 Learner 的新实例。

参数
cache_data用于缓存预测的矩阵。
返回
创建的学习器。

◆ Ctx()

virtual Context const* xgboost::Learner::Ctx ( ) const
纯虚函数

返回此 Booster 的上下文对象。

◆ DelAttr()

virtual bool xgboost::Learner::DelAttr ( const std::string &  key)
纯虚函数

从 booster 中删除属性。

参数
key属性的键。
返回
键是否在 booster 的属性中找到。

◆ DumpModel()

virtual std::vector<std::string> xgboost::Learner::DumpModel ( const FeatureMap fmap,
bool  with_stats,
std::string  format 
)
纯虚函数

以请求的格式转储模型

参数
fmap可能有助于解释特征的特征图
with_stats转储模型时的额外统计信息
format转储模型的格式
返回
booster 转储的向量。

◆ EvalOneIter()

virtual std::string xgboost::Learner::EvalOneIter ( int  iter,
const std::vector< std::shared_ptr< DMatrix >> &  data_sets,
const std::vector< std::string > &  data_names 
)
纯虚函数

使用配置的指标评估特定迭代的模型。

参数
iter迭代次数
data_sets要评估的数据集。
data_names每个数据集的名称
返回
对应于评估结果的字符串

◆ GetAttr()

virtual bool xgboost::Learner::GetAttr ( const std::string &  key,
std::string *  out 
) const
纯虚函数

从 booster 获取属性。该属性将与 booster 一起保存。

参数
key属性的键。
out输出值。
返回
键是否存在于 booster 的属性中。

◆ GetAttrNames()

virtual std::vector<std::string> xgboost::Learner::GetAttrNames ( ) const
纯虚函数

从 booster 获取属性名称向量。

返回
属性名称字符串向量。

◆ GetConfigurationArguments()

virtual const std::map<std::string, std::string>& xgboost::Learner::GetConfigurationArguments ( ) const
纯虚函数

获取学习器当前存储的配置参数。

返回
表示配置参数的键值对

◆ GetFeatureNames()

virtual void xgboost::Learner::GetFeatureNames ( std::vector< std::string > *  fn) const
纯虚函数

获取当前 booster 的特征名称。

参数
fn输出特征名称

◆ GetFeatureTypes()

virtual void xgboost::Learner::GetFeatureTypes ( std::vector< std::string > *  ft) const
纯虚函数

获取当前 booster 的特征类型。

参数
fn输出特征类型

◆ GetNumFeature()

virtual bst_feature_t xgboost::Learner::GetNumFeature ( ) const
纯虚函数

获取 booster 的特征数量。

返回
特征数量

◆ GetThreadLocal()

virtual XGBAPIThreadLocalEntry& xgboost::Learner::GetThreadLocal ( ) const
纯虚函数

◆ Groups()

virtual std::uint32_t xgboost::Learner::Groups ( ) const
纯虚函数

获取模型的输出组数量。

◆ InplacePredict()

virtual void xgboost::Learner::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 
)
纯虚函数

原地预测。

参数
p_fmat包含数据和相关元信息的代理 DMatrix
type预测类型。
missing数据中的缺失值。
[in,out]out_preds指向输出预测向量的指针。
layer_begin用于预测的增强树层的起始。
layer_end增强层结束。0 表示不限制树。

◆ LoadModel()

void xgboost::Learner::LoadModel ( Json const &  in)
override纯虚

从JSON对象加载模型

参数
in要从中加载模型的 JSON 对象。

实现 xgboost::Model

◆ Predict()

virtual void xgboost::Learner::Predict ( std::shared_ptr< DMatrix 数据,
bool  output_margin,
HostDeviceVector< bst_float > *  out_preds,
bst_layer_t  layer_begin,
bst_layer_t  layer_end,
bool  training = false,
bool  pred_leaf = false,
bool  pred_contribs = false,
bool  approx_contribs = false,
bool  pred_interactions = false 
)
纯虚函数

给定模型进行预测。

参数
数据输入数据
output_margin是否只预测边际值而不是转换后的预测
out_preds存储预测的输出向量
layer_begin用于预测的增强树层的起始。
layer_end增强层结束。0 表示不限制树。
training预测结果是否用于训练
pred_leaf是否只预测增强树预测器中每棵树的叶子索引
pred_contribs是否只预测特征贡献
approx_contribs是否近似特征贡献以提高速度
pred_interactions是否计算特征对贡献

◆ Reset()

virtual void xgboost::Learner::Reset ( )
纯虚函数

重置booster对象以释放用于训练的数据缓存。

◆ SaveModel()

void xgboost::Learner::SaveModel ( Json out) const
override纯虚

将模型配置保存到JSON对象

参数
out要保存模型的 JSON 容器。

实现 xgboost::Model

◆ SetAttr()

virtual void xgboost::Learner::SetAttr ( const std::string &  key,
const std::string &  value 
)
纯虚函数

为 Booster 设置附加属性。

该属性将与 booster 一起保存。

参数
key属性的键。
value属性的值。

◆ SetFeatureNames()

virtual void xgboost::Learner::SetFeatureNames ( std::vector< std::string > const &  fn)
纯虚函数

为当前 booster 设置特征名称。

参数
fn输入特征名称

◆ SetFeatureTypes()

virtual void xgboost::Learner::SetFeatureTypes ( std::vector< std::string > const &  ft)
纯虚函数

为当前 booster 设置特征类型。

参数
ft输入特征类型。

◆ SetParam()

virtual void xgboost::Learner::SetParam ( const std::string &  key,
const std::string &  value 
)
纯虚函数

设置 booster 参数。

该属性将不会与 booster 一起保存

参数
key参数的键
value参数的值

◆ SetParams()

virtual void xgboost::Learner::SetParams ( Args const &  args)
纯虚函数

一次性设置多个参数。

参数
args参数。

◆ Slice()

virtual Learner* xgboost::Learner::Slice ( bst_layer_t  begin,
bst_layer_t  end,
bst_layer_t  步长,
bool *  out_of_bound 
)
纯虚函数

切片模型。

有关层参数,请参见 InplacePredict。

参数
步长切片之间的步长。
out_of_bound如果结束层超出范围,则返回 true。
返回
切片模型。

◆ UpdateOneIter()

virtual void xgboost::Learner::UpdateOneIter ( std::int32_t  iter,
std::shared_ptr< DMatrix 训练 
)
纯虚函数

使用指定的目标函数更新模型一次迭代。

参数
iter当前迭代次数
训练数据矩阵的引用。

成员数据文档

◆ ctx_

Context xgboost::Learner::ctx_
protected

训练参数。

◆ gbm_

std::unique_ptr<GradientBooster> xgboost::Learner::gbm_
protected

模型使用的梯度助推器。

◆ metrics_

std::vector<std::unique_ptr<Metric> > xgboost::Learner::metrics_
protected

用于评估模型的评估指标。

◆ obj_

std::unique_ptr<ObjFunction> xgboost::Learner::obj_
protected

目标函数


此类的文档由以下文件生成