philsupertramp/game-math
|
#include <DecisionTree.h>
Public Member Functions | |
DecisionTree (int min_samples_per_split=2, int max_depth=10, ImpurityMeasure decision_method=ImpurityMeasure::GINI) | |
double | impurity (const Matrix< double > &x) |
double | information_gain (const Matrix< double > &parent, const Matrix< double > &left_child, const Matrix< double > &right_child) |
struct DataSplit | best_split (const Matrix< double > &X, const Matrix< double > &y) |
DecisionNode * | GetRootNode () const |
void | fit (const Matrix< double > &X, const Matrix< double > &y) override |
Matrix< double > | predict (const Matrix< double > &X) override |
Matrix< double > | transform (const Matrix< double > &in) override |
virtual void | fit (const Matrix< double > &X, const Matrix< double > &y)=0 |
virtual Matrix< double > | predict (const Matrix< double > &)=0 |
virtual Matrix< double > | transform (const Matrix< double > &)=0 |
Private Member Functions | |
DecisionNode * | build_tree (const Matrix< double > &X, const Matrix< double > &y, int depth=0) |
double | _predict (const Matrix< double > &x, DecisionNode *node) |
void | render_node (std::ostream &ostr, DecisionNode *node, const char *side, int depth) const |
Private Attributes | |
ImpurityMeasure | _decision_method |
int | _max_depth = 10 |
int | _min_samples_per_split = 2 |
DecisionNode * | base_node |
Friends | |
std::ostream & | operator<< (std::ostream &ostr, const DecisionTree &tree) |
Decision (Bi-)Tree implementation
|
inline |
|
inlineprivate |
Method to recursively traverse the tree to perform a prediction
x | input value(s) |
node | the current node to evaluate |
|
inline |
|
inlineprivate |
Method to recursively build decision tree nodes.
Uses pruning to decide to split the data further. Class-Hyperparameters:
X | input data of current node |
y | related class labels |
|
inlineoverridevirtual |
Implements training algorithm
X | array-like with the shape: [n_samples, n_features] |
y | array-like with shape: [n_samples, 1] |
Implements Predictor.
|
inline |
|
inline |
|
inline |
Calculates the information gain of a set of values given a split of two children.
Note: Pass your labels in here, not your input data!
parent | super set of label values |
left_child | left split of parent set |
right_child | right split of parent set |
|
inlineprivate |
Implements Predictor.
|
friend |
|
private |
|
private |
|
private |
|
private |