Decision tree. More...
#include <DecisionTree.hpp>
Public Types | |
typedef Eigen::Ref< const Eigen::VectorXd > | arg_type |
typedef Y | value_type |
typedef DecisionTrees::Node< Y > | Node |
typedef DecisionTrees::SplitNode< Y > | SplitNode |
typedef DecisionTrees::LeafNode< Y > | LeafNode |
Public Member Functions | |
DecisionTree (std::unique_ptr< Node > &&root) | |
Constructs a decision tree by taking ownership of a root node. More... | |
DecisionTree (DecisionTree< Y > &&other) noexcept | |
Move constructor. More... | |
DecisionTree (const DecisionTree< Y > &other) | |
Copy constructor. More... | |
DecisionTree< Y > & | operator= (DecisionTree< Y > &&other) noexcept |
Move assignment operator. More... | |
DecisionTree< Y > & | operator= (const DecisionTree< Y > &other) |
Copy assignment operator. More... | |
Y | operator() (arg_type x) const |
Returns a prediction given a feature vector. More... | |
unsigned int | count_nodes () const |
Counts nodes in the tree. | |
unsigned int | count_leaf_nodes () const |
Counts leaf nodes in the tree. | |
double | original_error () const |
Returns the prediction error for training data before any splits are made. | |
double | total_leaf_error () const |
Returns the total prediction error for training data after all splits. | |
double | cost_complexity (double alpha) const |
Calculates cost-complexity measure. More... | |
bool | remove_weakest_link (const double max_allowed_error_increase) |
Finds the weakest link and removes it, if the error does not increase too much. More... | |
unsigned int | number_lowest_split_nodes () const |
Counts lowest split nodes. More... | |
Decision tree.
Data points are in columns.
Y | Type of predicted value (integer for classification, real for regression). |
typedef Eigen::Ref<const Eigen::VectorXd> ml::DecisionTree< Y >::arg_type |
< Type for feature vector.
typedef Y ml::DecisionTree< Y >::value_type |
Type of predicted value (integer for classification, real for regression).
typedef DecisionTrees::Node<Y> ml::DecisionTree< Y >::Node |
Tree node. Nodes are split (non-terminal) or leaf (terminal).
typedef DecisionTrees::SplitNode<Y> ml::DecisionTree< Y >::SplitNode |
Non-terminal node, which splits data depending on a threshold value of some feature.
typedef DecisionTrees::LeafNode<Y> ml::DecisionTree< Y >::LeafNode |
Terminal node, which returns a constant prediction value for features which ended up on it.
|
inline |
Constructs a decision tree by taking ownership of a root node.
[in,out] | root | Non-null root node pointer. |
std::invalid_argument | If root or root->parent is null. |
|
inlinenoexcept |
Move constructor.
[in,out] | other | Moved tree. |
|
inline |
Copy constructor.
[in] | other | Copied tree. |
|
inlinenoexcept |
Move assignment operator.
[in,out] | other | Moved tree. |
|
inline |
Copy assignment operator.
[in] | other | Copied tree. |
|
inline |
Returns a prediction given a feature vector.
[in] | x | Feature vector. |
|
inline |
Calculates cost-complexity measure.
[in] | alpha | Complexity penalty per each leaf node. |
alpha
times the number of leaf nodes.
|
inline |
Finds the weakest link and removes it, if the error does not increase too much.
A "weakest link" is a split node which can be collapsed with the minimum increase of total_leaf_error(). Only the lowest split node can be a weakest link.
[in] | max_allowed_error_increase | Maximum allowed increase in total leaf error. |
std::domain_error | If max_allowed_error_increase < 0. |
|
inline |
Counts lowest split nodes.