Page Speed Optimization Libraries  1.9.32.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Member Functions | List of all members
net_instaweb::DecisionTree Class Reference

#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
 

Detailed Description

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.

Constructor & Destructor Documentation

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.

Member Function Documentation

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.

Todo:
TODO(stevensr): The ordering of measurements in the sample will become more concrete when the feature measurement logic is committed.

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