Medial Code Documentation
Loading...
Searching...
No Matches
Data Structures | Public Member Functions | Static Public Member Functions
LightGBM::Tree Class Reference

Tree model. More...

#include <tree.h>

Public Member Functions

 Tree (int max_leaves)
 Constructor.
 
 Tree (const char *str, size_t *used_len)
 Construtor, from a string.
 
int Split (int leaf, int feature, int real_feature, uint32_t threshold_bin, double threshold_double, double left_value, double right_value, int left_cnt, int right_cnt, float gain, MissingType missing_type, bool default_left)
 Performing a split on tree leaves.
 
int SplitCategorical (int leaf, int feature, int real_feature, const uint32_t *threshold_bin, int num_threshold_bin, const uint32_t *threshold, int num_threshold, double left_value, double right_value, int left_cnt, int right_cnt, float gain, MissingType missing_type)
 Performing a split on tree leaves, with categorical feature.
 
double LeafOutput (int leaf) const
 Get the output of one leaf.
 
void SetLeafOutput (int leaf, double output)
 Set the output of one leaf.
 
void AddPredictionToScore (const Dataset *data, data_size_t num_data, double *score) const
 Adding prediction value of this tree model to scores.
 
void AddPredictionToScore (const Dataset *data, const data_size_t *used_data_indices, data_size_t num_data, double *score) const
 Adding prediction value of this tree model to scorese.
 
double Predict (const double *feature_values) const
 Prediction on one record.
 
double PredictByMap (const std::unordered_map< int, double > &feature_values) const
 
int PredictLeafIndex (const double *feature_values) const
 
int PredictLeafIndexByMap (const std::unordered_map< int, double > &feature_values) const
 
void PredictContrib (const double *feature_values, int num_features, double *output)
 
int num_leaves () const
 Get Number of leaves.
 
int leaf_depth (int leaf_idx) const
 Get depth of specific leaf.
 
int split_feature (int split_idx) const
 Get feature of specific split.
 
double split_gain (int split_idx) const
 
int data_count (int node) const
 Get the number of data points that fall at or below this node.
 
void Shrinkage (double rate)
 Shrinkage for the tree's output shrinkage rate (a.k.a learning rate) is used to tune the traning process.
 
double shrinkage () const
 
void AddBias (double val)
 
void AsConstantTree (double val)
 
std::string ToString () const
 Serialize this object to string.
 
std::string ToJSON () const
 Serialize this object to json.
 
std::string ToIfElse (int index, bool predict_leaf_index) const
 Serialize this object to if-else statement.
 
void RecomputeMaxDepth ()
 

Static Public Member Functions

static bool IsZero (double fval)
 
static bool GetDecisionType (int8_t decision_type, int8_t mask)
 
static void SetDecisionType (int8_t *decision_type, bool input, int8_t mask)
 
static int8_t GetMissingType (int8_t decision_type)
 
static void SetMissingType (int8_t *decision_type, int8_t input)
 

Detailed Description

Tree model.

Constructor & Destructor Documentation

◆ Tree() [1/2]

LightGBM::Tree::Tree ( int  max_leaves)
explicit

Constructor.

Parameters
max_leavesThe number of max leaves

◆ Tree() [2/2]

LightGBM::Tree::Tree ( const char *  str,
size_t *  used_len 
)

Construtor, from a string.

Parameters
strModel string
used_lenused count of str

Member Function Documentation

◆ AddPredictionToScore() [1/2]

void LightGBM::Tree::AddPredictionToScore ( const Dataset data,
const data_size_t used_data_indices,
data_size_t  num_data,
double *  score 
) const

Adding prediction value of this tree model to scorese.

Parameters
dataThe dataset
used_data_indicesIndices of used data
num_dataNumber of total data
scoreWill add prediction to score

◆ AddPredictionToScore() [2/2]

void LightGBM::Tree::AddPredictionToScore ( const Dataset data,
data_size_t  num_data,
double *  score 
) const

Adding prediction value of this tree model to scores.

Parameters
dataThe dataset
num_dataNumber of total data
scoreWill add prediction to score

◆ Predict()

double LightGBM::Tree::Predict ( const double *  feature_values) const
inline

Prediction on one record.

Parameters
feature_valuesFeature value of this record
Returns
Prediction result

◆ Shrinkage()

void LightGBM::Tree::Shrinkage ( double  rate)
inline

Shrinkage for the tree's output shrinkage rate (a.k.a learning rate) is used to tune the traning process.

Parameters
rateThe factor of shrinkage

◆ Split()

int LightGBM::Tree::Split ( int  leaf,
int  feature,
int  real_feature,
uint32_t  threshold_bin,
double  threshold_double,
double  left_value,
double  right_value,
int  left_cnt,
int  right_cnt,
float  gain,
MissingType  missing_type,
bool  default_left 
)

Performing a split on tree leaves.

Parameters
leafIndex of leaf to be split
featureIndex of feature; the converted index after removing useless features
real_featureIndex of feature, the original index on data
threshold_binThreshold(bin) of split
threshold_doubleThreshold on feature value
left_valueModel Left child output
right_valueModel Right child output
left_cntCount of left child
right_cntCount of right child
gainSplit gain
missing_typemissing type
default_leftdefault direction for missing value
Returns
The index of new leaf.

◆ SplitCategorical()

int LightGBM::Tree::SplitCategorical ( int  leaf,
int  feature,
int  real_feature,
const uint32_t *  threshold_bin,
int  num_threshold_bin,
const uint32_t *  threshold,
int  num_threshold,
double  left_value,
double  right_value,
int  left_cnt,
int  right_cnt,
float  gain,
MissingType  missing_type 
)

Performing a split on tree leaves, with categorical feature.

Parameters
leafIndex of leaf to be split
featureIndex of feature; the converted index after removing useless features
real_featureIndex of feature, the original index on data
threshold_binThreshold(bin) of split, use bitset to represent
num_threshold_binsize of threshold_bin
thresholdThresholds of real feature value, use bitset to represent
num_thresholdsize of threshold
left_valueModel Left child output
right_valueModel Right child output
left_cntCount of left child
right_cntCount of right child
gainSplit gain
Returns
The index of new leaf.

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