Page Speed Optimization Libraries
1.9.32.2
|
#include "decision_tree.h"
Classes | |
struct | Node |
Public Member Functions | |
DecisionTree (const Node *nodes, int num_nodes) | |
int | num_features () const |
double | Predict (std::vector< double > const &sample) const |
A simple decision tree classifier that can classify samples given to it into different classes. Is not able to train itself, rather the decision tree is created from an exported DecisionTreeClassifier generated by python sklearn (see http://scikit-learn.org/stable/modules/tree.html).
Nodes are defined by a tuple: (feature_index, feature_threshold, confidence, left_child, right_child) To make a prediction with the tree, we start from the root node and make a move to either the left child if (X[feature_index] <= feature_threshold), else we move to the right child. Thus, all inner nodes of the tree must have two children. We repeat this until we reach a leaf node, which has a prediction confidence. The prediction confidence generally indicates how confident we are that the sample belongs in the positive class. Typically you would accept the sample into the postive class if the confidence > 0.5.
net_instaweb::DecisionTree::DecisionTree | ( | const Node * | nodes, |
int | num_nodes | ||
) |
The nodes variable is expected to be statically allocated in the code, and this class will not take ownership of it.
double net_instaweb::DecisionTree::Predict | ( | std::vector< double > const & | sample | ) | const |
Predict whether this sample belongs in the positive or negative class, returning the confidence that it is in the positive class. The sample should contain measurements for each of the relevant features, indexed in the same order that was used to train the tree.