koho.cpp  1.0.0
Public Member Functions | Public Attributes | List of all members
koho::Tree Class Reference

Binary tree structure build up of nodes. More...

#include <decision_tree.h>

Collaboration diagram for koho::Tree:
Collaboration graph
[legend]

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< Nodenodes
 

Detailed Description

Binary tree structure build up of nodes.

Constructor & Destructor Documentation

◆ Tree()

koho::Tree::Tree ( ClassesIdx_t  n_classes,
FeaturesIdx_t  n_features 
)

Create a new tree without nodes.

Parameters
[in]n_classesNumber of classes.
[in]n_featuresNumber of features.

Member Function Documentation

◆ add_node()

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.

◆ calculate_feature_importances()

void koho::Tree::calculate_feature_importances ( double *  importances)

Calculate feature importances from the decision tree.

Parameters
[in,out]importancesFeature importances corresponding to all features [n_features].

◆ deserialize()

void koho::Tree::deserialize ( std::ifstream &  fin)

Deserialize.

◆ predict()

void koho::Tree::predict ( Features_t X,
SamplesIdx_t  n_samples,
double *  y_prob 
)

Predict classes probabilities for the test data.

Parameters
[in]XTest input samples [n_samples x n_features].
[in]n_samplesNumber of samples in the test data.
[in,out]y_probClass probabilities corresponding to the test input samples [n_samples x n_classes].

◆ serialize()

void koho::Tree::serialize ( std::ofstream &  fout)

Serialize.

Member Data Documentation

◆ max_depth

TreeDepthIdx_t koho::Tree::max_depth

◆ n_classes

ClassesIdx_t koho::Tree::n_classes

◆ n_features

FeaturesIdx_t koho::Tree::n_features

◆ node_count

NodesIdx_t koho::Tree::node_count

◆ nodes

std::vector<Node> koho::Tree::nodes

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