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

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

#include <tree_model.h>

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

结构  CategoricalSplitMatrix
 用于分类拆分的类似 CSR 的矩阵。更多...
 
结构  FVec
 可由 RegTree 使用,并可由稀疏特征向量构造的稠密特征向量。更多...
 
类  Node
 树节点更多...
 

公共类型

使用 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)
 根据 nid 获取节点。更多...
 
const Nodeoperator[] (int nid) const
 根据 nid 获取节点。更多...
 
const std::vector< Node > & GetNodes () const
 获取节点的常量引用。更多...
 
const std::vector< RTreeNodeStat > & GetStats () const
 获取统计信息的常量引用。更多...
 
RTreeNodeStatStat (int nid)
 根据 nid 获取节点统计信息。更多...
 
const RTreeNodeStatStat (int nid) const
 根据 nid 获取节点统计信息。更多...
 
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 ()
 获取最大深度。更多...
 
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 
)
内联显式

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

成员函数文档

◆ 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

获取节点的常量引用。

◆ 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

获取统计信息的常量引用。

◆ 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

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

common::Span<uint32_t const> xgboost::RegTree::NodeCats ( bst_node_t  nidx) const
inline

获取类别的位存储。

◆ NodeSplitType()

FeatureType xgboost::RegTree::NodeSplitType ( bst_node_t  nidx) const
inline

获取节点的拆分类型。

参数
nidx节点索引。
返回
此拆分的类型。对于叶节点,它始终是 kNumerical。

◆ NumExtraNodes()

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

除根节点外的额外节点数量。

◆ NumFeatures()

bst_feature_t xgboost::RegTree::NumFeatures ( ) const
inlinenoexcept

获取特征数量。

◆ NumNodes()

bst_node_t xgboost::RegTree::NumNodes ( ) const
inlinenoexcept

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

◆ NumTargets()

bst_target_t xgboost::RegTree::NumTargets ( ) const
inline

叶权重的大小。

◆ NumValidNodes()

bst_node_t xgboost::RegTree::NumValidNodes ( ) const
inlinenoexcept

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

◆ operator==()

bool xgboost::RegTree::operator== ( const RegTree b) const
inline

◆ operator[]() [1/2]

Node& xgboost::RegTree::operator[] ( int  nid)
inline

根据 nid 获取节点。

◆ operator[]() [2/2]

const Node& xgboost::RegTree::operator[] ( int  nid) const
inline

根据 nid 获取节点。

◆ Parent()

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

◆ RightChild()

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

◆ SaveModel()

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

将模型配置保存到JSON对象

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

实现 xgboost::Model

◆ SetLeaf()

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

为多目标树设置叶权重。

◆ Size()

bst_node_t xgboost::RegTree::Size ( ) const
inline

◆ SplitCond()

float xgboost::RegTree::SplitCond ( bst_node_t  nidx) const
inline

◆ SplitIndex()

bst_feature_t xgboost::RegTree::SplitIndex ( bst_node_t  nidx) const
inline

◆ Stat() [1/2]

RTreeNodeStat& xgboost::RegTree::Stat ( int  nid)
inline

根据 nid 获取节点统计信息。

◆ Stat() [2/2]

const RTreeNodeStat& xgboost::RegTree::Stat ( int  nid) const
inline

根据 nid 获取节点统计信息。

◆ WalkTree()

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

成员数据文档

◆ kDeletedNodeMarker

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

◆ kInvalidNodeId

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

◆ kRoot

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

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