MLpp
ml::DecisionTree< Y > Class Template Reference

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...
 
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...
 

Detailed Description

template<class Y>
class ml::DecisionTree< Y >

Decision tree.

Data points are in columns.

Template Parameters
YType of predicted value (integer for classification, real for regression).

Member Typedef Documentation

◆ arg_type

template<class Y >
typedef Eigen::Ref<const Eigen::VectorXd> ml::DecisionTree< Y >::arg_type

< Type for feature vector.

◆ value_type

template<class Y >
typedef Y ml::DecisionTree< Y >::value_type

Type of predicted value (integer for classification, real for regression).

◆ Node

template<class Y >
typedef DecisionTrees::Node<Y> ml::DecisionTree< Y >::Node

Tree node. Nodes are split (non-terminal) or leaf (terminal).

◆ SplitNode

template<class Y >
typedef DecisionTrees::SplitNode<Y> ml::DecisionTree< Y >::SplitNode

Non-terminal node, which splits data depending on a threshold value of some feature.

◆ LeafNode

template<class Y >
typedef DecisionTrees::LeafNode<Y> ml::DecisionTree< Y >::LeafNode

Terminal node, which returns a constant prediction value for features which ended up on it.

Constructor & Destructor Documentation

◆ DecisionTree() [1/3]

template<class Y >
ml::DecisionTree< Y >::DecisionTree ( std::unique_ptr< Node > &&  root)
inline

Constructs a decision tree by taking ownership of a root node.

Parameters
[in,out]rootNon-null root node pointer.
Exceptions
std::invalid_argumentIf root or root->parent is null.

◆ DecisionTree() [2/3]

template<class Y >
ml::DecisionTree< Y >::DecisionTree ( DecisionTree< Y > &&  other)
inlinenoexcept

Move constructor.

Parameters
[in,out]otherMoved tree.

◆ DecisionTree() [3/3]

template<class Y >
ml::DecisionTree< Y >::DecisionTree ( const DecisionTree< Y > &  other)
inline

Copy constructor.

Parameters
[in]otherCopied tree.

Member Function Documentation

◆ operator=() [1/2]

template<class Y >
DecisionTree<Y>& ml::DecisionTree< Y >::operator= ( DecisionTree< Y > &&  other)
inlinenoexcept

Move assignment operator.

Parameters
[in,out]otherMoved tree.

◆ operator=() [2/2]

template<class Y >
DecisionTree<Y>& ml::DecisionTree< Y >::operator= ( const DecisionTree< Y > &  other)
inline

Copy assignment operator.

Parameters
[in]otherCopied tree.

◆ operator()()

template<class Y >
Y ml::DecisionTree< Y >::operator() ( arg_type  x) const
inline

Returns a prediction given a feature vector.

Parameters
[in]xFeature vector.
Returns
Predicted value.

◆ cost_complexity()

template<class Y >
double ml::DecisionTree< Y >::cost_complexity ( double  alpha) const
inline

Calculates cost-complexity measure.

Parameters
[in]alphaComplexity penalty per each leaf node.
Returns
Total leaf error plus alpha times the number of leaf nodes.

◆ remove_weakest_link()

template<class Y >
bool ml::DecisionTree< Y >::remove_weakest_link ( const double  max_allowed_error_increase)
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.

Parameters
[in]max_allowed_error_increaseMaximum allowed increase in total leaf error.
Returns
Whether a node was removed.
Exceptions
std::domain_errorIf max_allowed_error_increase < 0.

◆ number_lowest_split_nodes()

template<class Y >
unsigned int ml::DecisionTree< Y >::number_lowest_split_nodes ( ) const
inline

Counts lowest split nodes.

Returns
Number of lowest split nodes.

The documentation for this class was generated from the following file: