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

Learner 类,用于执行训练和预测。这是 xgboost 训练的用户可见模块。加载/保存函数对应于 python/R 中使用的模型。 更多...

#include <learner.h>

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

公有成员函数

 ~Learner () override
 虚析构函数 更多...
 
virtual void Configure ()=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 LoadModel (dmlc::Stream *fi)=0
 
virtual void SaveModel (dmlc::Stream *fo) const =0
 
virtual void SetParams (Args const &args)=0
 一次设定多个参数。 更多...
 
virtual void SetParam (const std::string &key, const std::string &value)=0
 为增强器设定参数。 更多...
 
virtual uint32_t GetNumFeature () const =0
 获取增强器的特征数量。 更多...
 
virtual void SetAttr (const std::string &key, const std::string &value)=0
 为增强器设定附加属性。 更多...
 
virtual bool GetAttr (const std::string &key, std::string *out) const =0
 从增强器获取属性。该属性将随增强器一同保存。 更多...
 
virtual bool DelAttr (const std::string &key)=0
 从增强器删除属性。 更多...
 
virtual std::vector< std::string > GetAttrNames () const =0
 从增强器获取属性名称向量。 更多...
 
virtual void SetFeatureNames (std::vector< std::string > const &fn)=0
 为当前增强器设定特征名称。 更多...
 
virtual void GetFeatureNames (std::vector< std::string > *fn) const =0
 获取当前增强器的特征名称。 更多...
 
virtual void SetFeatureTypes (std::vector< std::string > const &ft)=0
 为当前增强器设定特征类型。 更多...
 
virtual void GetFeatureTypes (std::vector< std::string > *ft) 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 Reset ()=0
 重置增强器对象,释放用于训练的数据缓存。 更多...
 
virtual Context const * Ctx () const =0
 返回此增强器的上下文对象。 更多...
 
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)
 创建新的学习器实例。 更多...
 

保护属性

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()

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 train,
linalg::Matrix< GradientPair > *  in_gpair 
)
纯虚

使用 in_gpair 执行定制梯度提升。

注意
调用后 in_gpair 可能被修改。
参数
iter当前迭代次数
train数据矩阵的引用。
in_gpair输入梯度统计量。

◆ CalcFeatureScore()

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

计算特征分数。参阅 C API 文档中的输出。

◆ Configure()

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

根据设定的参数配置 Learner

◆ Create()

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

创建新的学习器实例。

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

◆ Ctx()

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

返回此增强器的上下文对象。

◆ DelAttr()

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

从增强器删除属性。

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

◆ DumpModel()

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

按请求格式转储模型

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

◆ 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
纯虚

从增强器获取属性。该属性将随增强器一同保存。

参数
key属性的键。
out输出值。
返回
键是否在增强器的属性中存在。

◆ GetAttrNames()

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

从增强器获取属性名称向量。

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

◆ 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
纯虚

获取当前增强器的特征名称。

参数
fn输出特征名称

◆ GetFeatureTypes()

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

获取当前增强器的特征类型。

参数
fn输出特征类型

◆ GetNumFeature()

virtual uint32_t xgboost::Learner::GetNumFeature ( ) const
纯虚

获取增强器的特征数量。

返回
特征数量

◆ 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数据中的缺失值。
[输入,输出]out_preds指向输出预测向量的指针。
layer_begin用于预测的提升树层的起始位置。
layer_end增强器层的结束位置。0 表示不限制树的数量。

◆ LoadModel() [1/2]

virtual void xgboost::Learner::LoadModel ( dmlc::Stream *  fi)
纯虚

◆ LoadModel() [2/2]

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

从 JSON 对象加载模型

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

实现 xgboost::Model

◆ Predict()

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

给定模型获取预测。

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

◆ Reset()

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

重置增强器对象,释放用于训练的数据缓存。

◆ SaveModel() [1/2]

virtual void xgboost::Learner::SaveModel ( dmlc::Stream *  fo) const
纯虚

◆ SaveModel() [2/2]

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 
)
纯虚

为增强器设定附加属性。

该属性将随增强器一同保存。

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

◆ SetFeatureNames()

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

为当前增强器设定特征名称。

参数
fn输入特征名称

◆ SetFeatureTypes()

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

为当前增强器设定特征类型。

参数
ft输入特征类型。

◆ SetParam()

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

为增强器设定参数。

该属性不会随增强器一同保存

参数
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  step,
bool *  out_of_bound 
)
纯虚

模型切片。

参阅 InplacePredict 中的层参数。

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

◆ UpdateOneIter()

virtual void xgboost::Learner::UpdateOneIter ( std::int32_t  iter,
std::shared_ptr< DMatrix train 
)
纯虚

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

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

成员数据文档

◆ ctx_

Context xgboost::Learner::ctx_
保护

训练参数。

◆ gbm_

std::unique_ptr<GradientBooster> xgboost::Learner::gbm_
保护

模型使用的梯度增强器。

◆ metrics_

std::vector<std::unique_ptr<Metric> > xgboost::Learner::metrics_
保护

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

◆ obj_

std::unique_ptr<ObjFunction> xgboost::Learner::obj_
保护

目标函数


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