xgboost
|
定义回归树作为最常见的树模型。 更多...
#include <tree_model.h>
类 | |
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) | |
构造函数,初始化树模型形状。 更多... | |
Node & | operator[] (int nid) |
根据节点ID获取节点 更多... | |
const Node & | operator[] (int nid) const |
根据节点ID获取节点 更多... | |
const std::vector< Node > & | GetNodes () const |
获取节点的 const 引用 更多... | |
const std::vector< RTreeNodeStat > & | GetStats () const |
获取统计信息的 const 引用 更多... | |
RTreeNodeStat & | Stat (int nid) |
根据节点ID获取节点统计信息 更多... | |
const RTreeNodeStat & | Stat (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 |
![]() | |
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 主要树模型中使用的数据结构。
|
inline |
|
inlineexplicit |
初始化树模型形状的构造函数。
void xgboost::RegTree::CalculateContributionsApprox | ( | const RegTree::FVec & | feat, |
std::vector< float > * | mean_values, | ||
bst_float * | out_contribs | ||
) | const |
计算给定根节点的近似特征贡献
feat | 密集特征向量,如果特征缺失,则该字段设置为 NaN |
out_contribs | 用于存储贡献的输出向量 |
|
inline |
将非叶节点更改为叶节点,并删除其子节点
rid | 节点的节点ID |
value | 新的叶节点值 |
|
inline |
将非叶节点折叠为叶节点,并删除其子节点
rid | 节点的节点ID |
value | 新的叶节点值 |
|
inline |
|
inline |
std::string xgboost::RegTree::DumpModel | ( | const FeatureMap & | fmap, |
bool | with_stats, | ||
std::string | format | ||
) | const |
以请求的格式将模型转储为文本字符串
fmap | 特征映射,有助于解释特征 |
with_stats | 是否也转储统计信息 |
format | 转储模型的格式 |
bool xgboost::RegTree::Equal | ( | const RegTree & | b | ) | const |
从用户的角度比较两棵树是否相等。仅比较非删除节点。
b | 另一棵树。 |
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_hess | Hessian 之和。 |
left_sum | 左叶节点的 Hessian 之和。 |
right_sum | 右叶节点的 Hessian 之和。 |
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_hess | Hessian 之和。 |
left_sum | 左叶节点的 Hessian 之和。 |
right_sum | 右叶节点的 Hessian 之和。 |
leaf_right_child | 叶节点的右子节点索引,默认为 kInvalidNodeId,一些更新器使用叶节点的右子节点索引作为标记 |
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 | ||
) |
为多目标树将叶节点扩展为两个额外的叶节点。
|
inline |
|
inline |
获取当前深度
nid | 节点ID |
|
inline |
获取多目标树的底层实现。
|
inline |
获取节点的 const 引用
bst_node_t xgboost::RegTree::GetNumLeaves | ( | ) | const |
bst_node_t xgboost::RegTree::GetNumSplitNodes | ( | ) | const |
|
inline |
|
inline |
|
inline |
获取所有节点的分割类型。
|
inline |
获取统计信息的 const 引用
|
inline |
此树是否具有类别分割。
|
inline |
|
inline |
|
inline |
此树是否为多目标树。
|
inline |
|
inline |
void xgboost::RegTree::Load | ( | dmlc::Stream * | fi | ) |
从流中加载模型
fi | 输入流 |
|
overridevirtual |
|
inline |
获取最大深度
|
inline |
获取最大深度
nid | 节点ID |
|
inline |
common::Span<uint32_t const> xgboost::RegTree::NodeCats
|
inline |
|
bst_node_t xgboost::RegTree::NumExtraNodes |
inlinenoexcept
|
bst_node_t xgboost::RegTree::NumExtraNodes |
bst_feature_t xgboost::RegTree::NumFeatures
|
bst_node_t xgboost::RegTree::NumExtraNodes |
bst_node_t xgboost::RegTree::NumNodes
|
inline |
bst_target_t xgboost::RegTree::NumTargets
|
bst_node_t xgboost::RegTree::NumExtraNodes |
bst_node_t xgboost::RegTree::NumValidNodes
|
inline |
|
inline |
◆ Save() | ( | dmlc::Stream * | void xgboost::RegTree::Save | ) | const |
fo
void xgboost::RegTree::Save | 将模型保存到流 |
|
inline |
weight
|
inline |
|
inline |
|
inline |
|
inline |
RTreeNodeStat& xgboost::RegTree::Stat
|
inline |
RTreeNodeStat& xgboost::RegTree::Stat
|
inline |
|
constexpr uint32_t xgboost::RegTree::kDeletedNodeMarker = std::numeric_limits<uint32_t>::max() |
|
constexpr uint32_t xgboost::RegTree::kDeletedNodeMarker = std::numeric_limits<uint32_t>::max() |
|
constexpr uint32_t xgboost::RegTree::kDeletedNodeMarker = std::numeric_limits<uint32_t>::max() |