|
koho.cpp
1.1.0
|
Binary tree structure build up of nodes. More...
#include <decision_tree.h>

Public Member Functions | |
| Tree (OutputsIdx_t n_outputs, std::vector< ClassesIdx_t > n_classes, FeaturesIdx_t n_features) | |
| Create a new tree without nodes. More... | |
| Tree (OutputsIdx_t n_outputs, ClassesIdx_t *n_classes_ptr, FeaturesIdx_t n_features) | |
| Create a new tree without nodes for Python binding. More... | |
| Tree () | |
| Create a new tree without nodes for Python binding using pickle. 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< 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 | |
| OutputsIdx_t | n_outputs |
| std::vector< ClassesIdx_t > | n_classes |
| ClassesIdx_t | n_classes_max |
| 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 | ( | OutputsIdx_t | n_outputs, |
| std::vector< ClassesIdx_t > | n_classes, | ||
| FeaturesIdx_t | n_features | ||
| ) |
Create a new tree without nodes.
| [in] | n_outputs | Number of outputs. |
| [in] | n_classes | Number of classes for each output. |
| [in] | n_features | Number of features. |
| koho::Tree::Tree | ( | OutputsIdx_t | n_outputs, |
| ClassesIdx_t * | n_classes_ptr, | ||
| FeaturesIdx_t | n_features | ||
| ) |
Create a new tree without nodes for Python binding.
| [in] | n_outputs | Number of outputs. |
| [in] | n_classes | Number of classes for each output. |
| [in] | n_features | Number of features. |
|
inline |
Create a new tree without nodes for Python binding using pickle.
| 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< 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_outputs x n_classes_max]. We use n_classes_max to create a nice 3D array to hold the predicted values x samples x classes as the number of classes can be different for different outputs. |
Using 1d array addressing for X and y_prob to support efficient Cython bindings to Python using memory views.
| void koho::Tree::serialize | ( | std::ofstream & | fout | ) |
Serialize.
| TreeDepthIdx_t koho::Tree::max_depth |
| std::vector<ClassesIdx_t> koho::Tree::n_classes |
| ClassesIdx_t koho::Tree::n_classes_max |
| FeaturesIdx_t koho::Tree::n_features |
| OutputsIdx_t koho::Tree::n_outputs |
| NodesIdx_t koho::Tree::node_count |
| std::vector<Node> koho::Tree::nodes |
1.8.13