|
xgboost
|
define regression tree to be the most common tree model. More...
#include <tree_model.h>


Classes | |
| struct | CategoricalSplitMatrix |
| CSR-like matrix for categorical splits. More... | |
| struct | FVec |
| dense feature vector that can be taken by RegTree and can be construct from sparse feature vector. More... | |
| class | Node |
| tree node More... | |
Public Types | |
| using | SplitCondT = float |
Public Member Functions | |
| void | ChangeToLeaf (bst_node_t nidx, float value) |
| Change a non leaf node to a leaf node, delete its children. More... | |
| void | CollapseToLeaf (bst_node_t nidx, float value) |
| Collapse a non leaf node to a leaf node, delete its children. More... | |
| RegTree () | |
| RegTree (bst_target_t n_targets, bst_feature_t n_features) | |
| Constructor that initializes the tree model with shape. More... | |
| Node & | operator[] (bst_node_t nidx) |
| get node given nid More... | |
| common::Span< Node const > | GetNodes (DeviceOrd device) const |
| Get const reference to nodes. More... | |
| common::Span< RTreeNodeStat const > | GetStats (DeviceOrd device) const |
| Get const reference to stats. More... | |
| RTreeNodeStat & | Stat (int nid) |
| get node statistics given nid More... | |
| void | LoadModel (Json const &in) override |
| load the model from a JSON object More... | |
| void | SaveModel (Json *out) const override |
| saves the model config to a JSON object More... | |
| bool | operator== (const RegTree &b) const |
| bool | Equal (const RegTree &b) const |
| Compares whether 2 trees are equal from a user's perspective. The equality compares only non-deleted nodes. More... | |
| 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) |
| Expands a leaf node into two additional leaf nodes. More... | |
| 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, float loss_chg, float sum_hess, float left_sum, float right_sum) |
| Expands a leaf node into two additional leaf nodes for a multi-target tree. More... | |
| void | SetLeaves (std::vector< bst_node_t > leaves, common::Span< float const > weights) |
| Set all leaf weights for a multi-target tree. More... | |
| 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) |
| Expands a leaf node with categories. More... | |
| bool | HasCategoricalSplit () const |
| Whether this tree has categorical split. More... | |
| bool | IsMultiTarget () const |
| Whether this is a multi-target tree. More... | |
| bst_target_t | NumTargets () const |
| The size of leaf weight. More... | |
| auto | GetMultiTargetTree () const |
| Get the underlying implementaiton of multi-target tree. More... | |
| bst_feature_t | NumFeatures () const noexcept |
| Get the number of features. More... | |
| bst_node_t | NumNodes () const noexcept |
| Get the total number of nodes including deleted ones in this tree. More... | |
| bst_node_t | NumValidNodes () const noexcept |
| Get the total number of valid nodes in this tree. More... | |
| bst_node_t | NumExtraNodes () const noexcept |
| number of extra nodes besides the root More... | |
| bst_node_t | GetNumLeaves () const |
| bst_node_t | GetNumSplitNodes () const |
| bst_node_t | GetDepth (bst_node_t nidx) const |
| Get the depth of a node. More... | |
| void | SetRoot (linalg::VectorView< float const > weight, float sum_hess) |
| Set the root weight and statistics for a multi-target tree. More... | |
| bst_node_t | MaxDepth () const |
| Get the maximum depth. More... | |
| std::string | DumpModel (const FeatureMap &fmap, bool with_stats, std::string format) const |
| dump the model in the requested format as a text string More... | |
| common::Span< FeatureType const > | GetSplitTypes (DeviceOrd device) const |
| Get split types for all nodes. More... | |
| common::Span< uint32_t const > | GetSplitCategories (DeviceOrd device) const |
| auto const & | GetSplitCategoriesPtr () const |
| CategoricalSplitMatrix | GetCategoriesMatrix (DeviceOrd device) const |
| bst_node_t | LeftChild (bst_node_t nidx) const |
| bst_node_t | RightChild (bst_node_t nidx) const |
| bst_node_t | Size () const |
| RegTree * | Copy () const |
| tree::ScalarTreeView | HostScView () const |
| tree::MultiTargetTreeView | HostMtView () const |
Public Member Functions inherited from xgboost::Model | |
| virtual | ~Model ()=default |
Static Public Attributes | |
| 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} |
define regression tree to be the most common tree model.
This is the data structure used in xgboost's major tree models.
| using xgboost::RegTree::SplitCondT = float |
|
inline |
|
inlineexplicit |
Constructor that initializes the tree model with shape.
|
inline |
Change a non leaf node to a leaf node, delete its children.
| nidx | Node id |
| value | The new leaf value |
|
inline |
Collapse a non leaf node to a leaf node, delete its children.
| nidx | Node id |
| value | The new leaf value |
| RegTree* xgboost::RegTree::Copy | ( | ) | const |
| std::string xgboost::RegTree::DumpModel | ( | const FeatureMap & | fmap, |
| bool | with_stats, | ||
| std::string | format | ||
| ) | const |
dump the model in the requested format as a text string
| fmap | feature map that may help give interpretations of feature |
| with_stats | whether dump out statistics as well |
| format | the format to dump the model in |
| bool xgboost::RegTree::Equal | ( | const RegTree & | b | ) | const |
Compares whether 2 trees are equal from a user's perspective. The equality compares only non-deleted nodes.
| b | The other tree. |
| 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 | ||
| ) |
Expands a leaf node with categories.
| nid | The node index to expand. |
| split_index | Feature index of the split. |
| split_cat | The bitset containing categories |
| default_left | True to default left. |
| base_weight | The base weight, before learning rate. |
| left_leaf_weight | The left leaf weight for prediction, modified by learning rate. |
| right_leaf_weight | The right leaf weight for prediction, modified by learning rate. |
| loss_change | The loss change. |
| sum_hess | The sum hess. |
| left_sum | The sum hess of left leaf. |
| right_sum | The sum hess of right leaf. |
| 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 |
||
| ) |
Expands a leaf node into two additional leaf nodes.
| nid | The node index to expand. |
| split_index | Feature index of the split. |
| split_value | The split condition. |
| default_left | True to default left. |
| base_weight | The base weight, before learning rate. |
| left_leaf_weight | The left leaf weight for prediction, modified by learning rate. |
| right_leaf_weight | The right leaf weight for prediction, modified by learning rate. |
| loss_change | The loss change. |
| sum_hess | The sum hess. |
| left_sum | The sum hess of left leaf. |
| right_sum | The sum hess of right leaf. |
| leaf_right_child | The right child index of leaf, by default kInvalidNodeId, some updaters use the right child index of leaf as a marker |
| 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, | ||
| float | loss_chg, | ||
| float | sum_hess, | ||
| float | left_sum, | ||
| float | right_sum | ||
| ) |
Expands a leaf node into two additional leaf nodes for a multi-target tree.
| gain | The gain (loss change) from this split. |
| sum_hess | The sum of hessians for the parent node (coverage). |
| left_sum | The sum of hessians for the left child (coverage). |
| right_sum | The sum of hessians for the right child (coverage). |
|
inline |
| bst_node_t xgboost::RegTree::GetDepth | ( | bst_node_t | nidx | ) | const |
Get the depth of a node.
|
inline |
Get the underlying implementaiton of multi-target tree.
|
inline |
Get const reference to nodes.
| bst_node_t xgboost::RegTree::GetNumLeaves | ( | ) | const |
| bst_node_t xgboost::RegTree::GetNumSplitNodes | ( | ) | const |
|
inline |
|
inline |
|
inline |
Get split types for all nodes.
|
inline |
Get const reference to stats.
|
inline |
Whether this tree has categorical split.
| tree::MultiTargetTreeView xgboost::RegTree::HostMtView | ( | ) | const |
| tree::ScalarTreeView xgboost::RegTree::HostScView | ( | ) | const |
|
inline |
Whether this is a multi-target tree.
|
inline |
|
overridevirtual |
load the model from a JSON object
| in | JSON object where to load the model from |
Implements xgboost::Model.
| bst_node_t xgboost::RegTree::MaxDepth | ( | ) | const |
Get the maximum depth.
|
inlinenoexcept |
number of extra nodes besides the root
|
inlinenoexcept |
Get the number of features.
|
inlinenoexcept |
Get the total number of nodes including deleted ones in this tree.
|
inline |
The size of leaf weight.
|
inlinenoexcept |
Get the total number of valid nodes in this tree.
|
inline |
|
inline |
get node given nid
|
inline |
|
overridevirtual |
saves the model config to a JSON object
| out | JSON container where to save the model to |
Implements xgboost::Model.
| void xgboost::RegTree::SetLeaves | ( | std::vector< bst_node_t > | leaves, |
| common::Span< float const > | weights | ||
| ) |
Set all leaf weights for a multi-target tree.
The leaf weight can be different from the internal weight stored by ExpandNode This function is used to set the leaf at the end of tree construction.
| leaves | The node indices for all leaves. This must contain all the leaves in this tree. |
| weights | Row-major matrix for leaf weights, each row contains a leaf specified by the leaves parameter. |
|
inline |
Set the root weight and statistics for a multi-target tree.
| weight | Internal split weight, with size equals to reduced targets. |
| sum_hess | The sum of hessians for the root node (coverage). |
|
inline |
|
inline |
get node statistics given nid
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |