koho.cpp
1.0.0
|
Binary tree structure build up of nodes. More...
#include <decision_tree.h>
Public Member Functions | |
Tree (ClassesIdx_t n_classes, FeaturesIdx_t n_features) | |
Create a new tree without nodes. More... | |
NodesIdx_t | add_node (TreeDepthIdx_t depth, NodesIdx_t parent_id, bool is_left, FeaturesIdx_t feature, int NA, Features_t threshold, const std::vector< Histogram_t > &histogram, double impurity, double improvement) |
Add a new node to the tree. More... | |
void | predict (Features_t *X, SamplesIdx_t n_samples, double *y_prob) |
Predict classes probabilities for the test data. More... | |
void | calculate_feature_importances (double *importances) |
Calculate feature importances from the decision tree. More... | |
void | serialize (std::ofstream &fout) |
Serialize. More... | |
void | deserialize (std::ifstream &fin) |
Deserialize. More... | |
Public Attributes | |
ClassesIdx_t | n_classes |
FeaturesIdx_t | n_features |
TreeDepthIdx_t | max_depth |
NodesIdx_t | node_count |
std::vector< Node > | nodes |
Binary tree structure build up of nodes.
koho::Tree::Tree | ( | ClassesIdx_t | n_classes, |
FeaturesIdx_t | n_features | ||
) |
Create a new tree without nodes.
[in] | n_classes | Number of classes. |
[in] | n_features | Number of features. |
NodesIdx_t koho::Tree::add_node | ( | TreeDepthIdx_t | depth, |
NodesIdx_t | parent_id, | ||
bool | is_left, | ||
FeaturesIdx_t | feature, | ||
int | NA, | ||
Features_t | threshold, | ||
const std::vector< Histogram_t > & | histogram, | ||
double | impurity, | ||
double | improvement | ||
) |
Add a new node to the tree.
The new node registers itself as the child of its parent.
void koho::Tree::calculate_feature_importances | ( | double * | importances | ) |
Calculate feature importances from the decision tree.
[in,out] | importances | Feature importances corresponding to all features [n_features]. |
void koho::Tree::deserialize | ( | std::ifstream & | fin | ) |
Deserialize.
void koho::Tree::predict | ( | Features_t * | X, |
SamplesIdx_t | n_samples, | ||
double * | y_prob | ||
) |
Predict classes probabilities for the test data.
[in] | X | Test input samples [n_samples x n_features]. |
[in] | n_samples | Number of samples in the test data. |
[in,out] | y_prob | Class probabilities corresponding to the test input samples [n_samples x n_classes]. |
void koho::Tree::serialize | ( | std::ofstream & | fout | ) |
Serialize.
TreeDepthIdx_t koho::Tree::max_depth |
ClassesIdx_t koho::Tree::n_classes |
FeaturesIdx_t koho::Tree::n_features |
NodesIdx_t koho::Tree::node_count |
std::vector<Node> koho::Tree::nodes |