xgboost
| 公共类型 | 公共成员函数 | 公共静态属性 | 所有成员列表
xgboost::RegTree 类参考

定义回归树作为最常见的树模型。 更多...

#include <tree_model.h>

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

struct  CategoricalSplitMatrix
 用于类别分割的 CSR 类矩阵。 更多...
 
struct  FVec
 RegTree 接受且可由稀疏特征向量构建的密集特征向量。 更多...
 
class  Node
 树节点 更多...
 

公共类型

using SplitCondT = bst_float
 

公共成员函数

void ChangeToLeaf (int rid, bst_float value)
 将非叶节点更改为叶节点,并删除其子节点 更多...
 
void CollapseToLeaf (int rid, bst_float value)
 将非叶节点折叠为叶节点,并删除其子节点 更多...
 
 RegTree ()
 
 RegTree (bst_target_t n_targets, bst_feature_t n_features)
 构造函数,初始化树模型形状。 更多...
 
Nodeoperator[] (int nid)
 根据节点ID获取节点 更多...
 
const Nodeoperator[] (int nid) const
 根据节点ID获取节点 更多...
 
const std::vector< Node > & GetNodes () const
 获取节点的 const 引用 更多...
 
const std::vector< RTreeNodeStat > & GetStats () const
 获取统计信息的 const 引用 更多...
 
RTreeNodeStatStat (int nid)
 根据节点ID获取节点统计信息 更多...
 
const RTreeNodeStatStat (int nid) const
 根据节点ID获取节点统计信息 更多...
 
void Load (dmlc::Stream *fi)
 从流中加载模型 更多...
 
void Save (dmlc::Stream *fo) const
 将模型保存到流 更多...
 
void LoadModel (Json const &in) override
 从 JSON 对象加载模型 更多...
 
void SaveModel (Json *out) const override
 将模型配置保存到 JSON 对象 更多...
 
bool operator== (const RegTree &b) const
 
template<typename Func >
void WalkTree (Func func) const
 
bool Equal (const RegTree &b) const
 从用户的角度比较两棵树是否相等。仅比较非删除节点。 更多...
 
void ExpandNode (bst_node_t nid, unsigned split_index, bst_float split_value, bool default_left, bst_float base_weight, bst_float left_leaf_weight, bst_float right_leaf_weight, bst_float loss_change, float sum_hess, float left_sum, float right_sum, bst_node_t leaf_right_child=kInvalidNodeId)
 将叶节点扩展为两个额外的叶节点。 更多...
 
void ExpandNode (bst_node_t nidx, bst_feature_t split_index, float split_cond, bool default_left, linalg::VectorView< float const > base_weight, linalg::VectorView< float const > left_weight, linalg::VectorView< float const > right_weight)
 为多目标树将叶节点扩展为两个额外的叶节点。 更多...
 
void ExpandCategorical (bst_node_t nid, bst_feature_t split_index, common::Span< const uint32_t > split_cat, bool default_left, bst_float base_weight, bst_float left_leaf_weight, bst_float right_leaf_weight, bst_float loss_change, float sum_hess, float left_sum, float right_sum)
 扩展带有类别的叶节点。 更多...
 
bool HasCategoricalSplit () const
 此树是否具有类别分割。 更多...
 
bool IsMultiTarget () const
 此树是否为多目标树。 更多...
 
bst_target_t NumTargets () const
 叶权重的尺寸。 更多...
 
auto GetMultiTargetTree () const
 获取多目标树的底层实现。 更多...
 
bst_feature_t NumFeatures () const noexcept
 获取特征数量。 更多...
 
bst_node_t NumNodes () const noexcept
 获取此树中包括已删除节点在内的节点总数。 更多...
 
bst_node_t NumValidNodes () const noexcept
 获取此树中有效节点的总数。 更多...
 
bst_node_t NumExtraNodes () const noexcept
 除根节点外的额外节点数 更多...
 
bst_node_t GetNumLeaves () const
 
bst_node_t GetNumSplitNodes () const
 
std::int32_t GetDepth (bst_node_t nid) const
 获取当前深度 更多...
 
void SetLeaf (bst_node_t nidx, linalg::VectorView< float const > weight)
 设置多目标树的叶权重。 更多...
 
int MaxDepth (int nid) const
 获取最大深度 更多...
 
int MaxDepth ()
 获取最大深度 更多...
 
void CalculateContributionsApprox (const RegTree::FVec &feat, std::vector< float > *mean_values, bst_float *out_contribs) const
 计算给定根节点的近似特征贡献。 更多...
 
std::string DumpModel (const FeatureMap &fmap, bool with_stats, std::string format) const
 以请求的格式将模型转储为文本字符串。 更多...
 
FeatureType NodeSplitType (bst_node_t nidx) const
 获取节点的分割类型。 更多...
 
std::vector< FeatureType > const & GetSplitTypes () const
 获取所有节点的分割类型。 更多...
 
common::Span< uint32_t const > GetSplitCategories () const
 
common::Span< uint32_t const > NodeCats (bst_node_t nidx) const
 获取类别的位存储。 更多...
 
auto const & GetSplitCategoriesPtr () const
 
CategoricalSplitMatrix GetCategoriesMatrix () const
 
bst_feature_t SplitIndex (bst_node_t nidx) const
 
float SplitCond (bst_node_t nidx) const
 
bool DefaultLeft (bst_node_t nidx) const
 
bst_node_t DefaultChild (bst_node_t nidx) const
 
bool IsRoot (bst_node_t nidx) const
 
bool IsLeaf (bst_node_t nidx) const
 
bst_node_t Parent (bst_node_t nidx) const
 
bst_node_t LeftChild (bst_node_t nidx) const
 
bst_node_t RightChild (bst_node_t nidx) const
 
bool IsLeftChild (bst_node_t nidx) const
 
bst_node_t Size () const
 
- 继承自 xgboost::Model 的公共成员函数
virtual ~Model ()=default
 

公共静态属性

static constexpr bst_node_t kInvalidNodeId {MultiTargetTree::InvalidNodeId()}
 
static constexpr uint32_t kDeletedNodeMarker = std::numeric_limits<uint32_t>::max()
 
static constexpr bst_node_t kRoot {0}
 

详细描述

定义回归树作为最常见的树模型。

这是 xgboost 主要树模型中使用的数据结构。

成员类型定义文档

◆ SplitCondT

构造函数与析构函数文档

◆ RegTree() [1/2]

xgboost::RegTree::RegTree ( )
inline

◆ RegTree() [2/2]

xgboost::RegTree::RegTree ( bst_target_t  n_targets,
bst_feature_t  n_features 
)
inlineexplicit

初始化树模型形状的构造函数。

成员函数文档

◆ CalculateContributionsApprox()

void xgboost::RegTree::CalculateContributionsApprox ( const RegTree::FVec feat,
std::vector< float > *  mean_values,
bst_float out_contribs 
) const

计算给定根节点的近似特征贡献

参数
feat密集特征向量,如果特征缺失,则该字段设置为 NaN
out_contribs用于存储贡献的输出向量

◆ ChangeToLeaf()

void xgboost::RegTree::ChangeToLeaf ( int  rid,
bst_float  value 
)
inline

将非叶节点更改为叶节点,并删除其子节点

参数
rid节点的节点ID
value新的叶节点值

◆ CollapseToLeaf()

void xgboost::RegTree::CollapseToLeaf ( int  rid,
bst_float  value 
)
inline

将非叶节点折叠为叶节点,并删除其子节点

参数
rid节点的节点ID
value新的叶节点值

◆ DefaultChild()

bst_node_t xgboost::RegTree::DefaultChild ( bst_node_t  nidx) const
inline

◆ DefaultLeft()

bool xgboost::RegTree::DefaultLeft ( bst_node_t  nidx) const
inline

◆ DumpModel()

std::string xgboost::RegTree::DumpModel ( const FeatureMap fmap,
bool  with_stats,
std::string  format 
) const

以请求的格式将模型转储为文本字符串

参数
fmap特征映射,有助于解释特征
with_stats是否也转储统计信息
format转储模型的格式
返回值
转储模型的字符串

◆ Equal()

bool xgboost::RegTree::Equal ( const RegTree b) const

从用户的角度比较两棵树是否相等。仅比较非删除节点。

参数
b另一棵树。

◆ ExpandCategorical()

void xgboost::RegTree::ExpandCategorical ( bst_node_t  nid,
bst_feature_t  split_index,
common::Span< const uint32_t >  split_cat,
bool  default_left,
bst_float  base_weight,
bst_float  left_leaf_weight,
bst_float  right_leaf_weight,
bst_float  loss_change,
float  sum_hess,
float  left_sum,
float  right_sum 
)

扩展带有类别的叶节点。

参数
nid要扩展的节点索引。
split_index分割的特征索引。
split_cat包含类别的位集
default_left默认向左时为真。
base_weight基础权重,学习率调整前。
left_leaf_weight左叶节点的预测权重,经学习率调整。
right_leaf_weight右叶节点的预测权重,经学习率调整。
loss_change损失变化。
sum_hessHessian 之和。
left_sum左叶节点的 Hessian 之和。
right_sum右叶节点的 Hessian 之和。

◆ ExpandNode() [1/2]

void xgboost::RegTree::ExpandNode ( bst_node_t  nid,
unsigned  split_index,
bst_float  split_value,
bool  default_left,
bst_float  base_weight,
bst_float  left_leaf_weight,
bst_float  right_leaf_weight,
bst_float  loss_change,
float  sum_hess,
float  left_sum,
float  right_sum,
bst_node_t  leaf_right_child = kInvalidNodeId 
)

将叶节点扩展为两个额外的叶节点。

参数
nid要扩展的节点索引。
split_index分割的特征索引。
split_value分割条件。
default_left默认向左时为真。
base_weight基础权重,学习率调整前。
left_leaf_weight左叶节点的预测权重,经学习率调整。
right_leaf_weight右叶节点的预测权重,经学习率调整。
loss_change损失变化。
sum_hessHessian 之和。
left_sum左叶节点的 Hessian 之和。
right_sum右叶节点的 Hessian 之和。
leaf_right_child叶节点的右子节点索引,默认为 kInvalidNodeId,一些更新器使用叶节点的右子节点索引作为标记

◆ ExpandNode() [2/2]

void xgboost::RegTree::ExpandNode ( bst_node_t  nidx,
bst_feature_t  split_index,
float  split_cond,
bool  default_left,
linalg::VectorView< float const >  base_weight,
linalg::VectorView< float const >  left_weight,
linalg::VectorView< float const >  right_weight 
)

为多目标树将叶节点扩展为两个额外的叶节点。

◆ GetCategoriesMatrix()

CategoricalSplitMatrix xgboost::RegTree::GetCategoriesMatrix ( ) const
inline

◆ GetDepth()

std::int32_t xgboost::RegTree::GetDepth ( bst_node_t  nid) const
inline

获取当前深度

参数
nid节点ID

◆ GetMultiTargetTree()

auto xgboost::RegTree::GetMultiTargetTree ( ) const
inline

获取多目标树的底层实现。

◆ GetNodes()

const std::vector<Node>& xgboost::RegTree::GetNodes ( ) const
inline

获取节点的 const 引用

◆ GetNumLeaves()

bst_node_t xgboost::RegTree::GetNumLeaves ( ) const

◆ GetNumSplitNodes()

bst_node_t xgboost::RegTree::GetNumSplitNodes ( ) const

◆ GetSplitCategories()

common::Span<uint32_t const> xgboost::RegTree::GetSplitCategories ( ) const
inline

◆ GetSplitCategoriesPtr()

auto const& xgboost::RegTree::GetSplitCategoriesPtr ( ) const
inline

◆ GetSplitTypes()

std::vector<FeatureType> const& xgboost::RegTree::GetSplitTypes ( ) const
inline

获取所有节点的分割类型。

◆ GetStats()

const std::vector<RTreeNodeStat>& xgboost::RegTree::GetStats ( ) const
inline

获取统计信息的 const 引用

◆ HasCategoricalSplit()

bool xgboost::RegTree::HasCategoricalSplit ( ) const
inline

此树是否具有类别分割。

◆ IsLeaf()

bool xgboost::RegTree::IsLeaf ( bst_node_t  nidx) const
inline

◆ IsLeftChild()

bool xgboost::RegTree::IsLeftChild ( bst_node_t  nidx) const
inline

◆ IsMultiTarget()

bool xgboost::RegTree::IsMultiTarget ( ) const
inline

此树是否为多目标树。

◆ IsRoot()

bool xgboost::RegTree::IsRoot ( bst_node_t  nidx) const
inline

◆ LeftChild()

bst_node_t xgboost::RegTree::LeftChild ( bst_node_t  nidx) const
inline

◆ Load()

void xgboost::RegTree::Load ( dmlc::Stream *  fi)

从流中加载模型

参数
fi输入流

◆ LoadModel()

void xgboost::RegTree::LoadModel ( Json const &  in)
overridevirtual

从 JSON 对象加载模型

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

实现了 xgboost::Model

◆ MaxDepth() [1/2]

int xgboost::RegTree::MaxDepth ( )
inline

获取最大深度

◆ MaxDepth() [2/2]

int xgboost::RegTree::MaxDepth ( int  nid) const
inline

获取最大深度

参数
nid节点ID

◆ 节点猫()

◆ NodeCats() ( bst_node_t  nidx) const
inline

common::Span<uint32_t const> xgboost::RegTree::NodeCats

获取类别的位存储。

◆ NodeSplitType() ( bst_node_t  nidx) const
inline

FeatureType xgboost::RegTree::NodeSplitType

参数
nidx获取节点的分割类型。
返回值
节点索引。

此分割的类型。对于叶节点,它总是 kNumerical。

◆ NumExtraNodes() ( ) const
bst_node_t xgboost::RegTree::NumExtraNodes

inlinenoexcept

除根节点外的额外节点数

◆ NumFeatures() ( ) const
bst_node_t xgboost::RegTree::NumExtraNodes

bst_feature_t xgboost::RegTree::NumFeatures

获取特征数量。

◆ NumNodes() ( ) const
bst_node_t xgboost::RegTree::NumExtraNodes

bst_node_t xgboost::RegTree::NumNodes

获取此树中包括已删除节点在内的节点总数。

◆ NumTargets() ( ) const
inline

bst_target_t xgboost::RegTree::NumTargets

叶权重的尺寸。

◆ NumValidNodes() ( ) const
bst_node_t xgboost::RegTree::NumExtraNodes

bst_node_t xgboost::RegTree::NumValidNodes

获取此树中有效节点的总数。

◆ operator==() ( const RegTree b) const
inline

bool xgboost::RegTree::operator==

◆ operator[]() [1/2] ( int  nid)
inline

Node& xgboost::RegTree::operator[]

根据节点ID获取节点

◆ operator[]() [2/2] ( int  nid) const
inline

Node& xgboost::RegTree::operator[]

const Node& xgboost::RegTree::operator[]

◆ Parent() ( bst_node_t  nidx) const
inline

bst_node_t xgboost::RegTree::Parent

◆ RightChild() ( bst_node_t  nidx) const
inline

bst_node_t xgboost::RegTree::RightChild

◆ Save() ( dmlc::Stream *  void xgboost::RegTree::Save) const

fo

参数
void xgboost::RegTree::Save将模型保存到流

输出流

◆ SaveModel() ( void xgboost::RegTree::SaveModel Json) const
overridevirtual

out

参数
Json将模型配置保存到 JSON 对象

用于保存模型的 JSON 容器

实现了 xgboost::Model

◆ SetLeaf() ( bst_node_t  nidx,
linalg::VectorView< float const >  void xgboost::RegTree::SetLeaf
)
inline

weight 

设置多目标树的叶权重。

◆ Size() ( ) const
inline

bst_node_t xgboost::RegTree::Size

◆ SplitCond() ( bst_node_t  nidx) const
inline

float xgboost::RegTree::SplitCond

◆ SplitIndex() ( bst_node_t  nidx) const
inline

bst_feature_t xgboost::RegTree::SplitIndex

◆ Stat() [1/2] ( int  nid)
inline

RTreeNodeStat& xgboost::RegTree::Stat

根据节点ID获取节点统计信息

◆ Stat() [2/2] ( int  nid) const
inline

RTreeNodeStat& xgboost::RegTree::Stat

const RTreeNodeStat& xgboost::RegTree::Stat

template<typename Func >
◆ WalkTree() ( void xgboost::RegTree::WalkTree Func ) const
inline

func

成员数据文档

◆ kDeletedNodeMarker
constexpr uint32_t xgboost::RegTree::kDeletedNodeMarker = std::numeric_limits<uint32_t>::max()

staticconstexpr

◆ kInvalidNodeId
constexpr uint32_t xgboost::RegTree::kDeletedNodeMarker = std::numeric_limits<uint32_t>::max()

constexpr bst_node_t xgboost::RegTree::kInvalidNodeId {MultiTargetTree::InvalidNodeId()}

◆ kRoot
constexpr uint32_t xgboost::RegTree::kDeletedNodeMarker = std::numeric_limits<uint32_t>::max()

constexpr bst_node_t xgboost::RegTree::kRoot {0}