CNum 0.2.1
CPU-optimized ML library for C++
Loading...
Searching...
No Matches
CNum::Model::Tree::GBModel< TreeType > Class Template Reference

A gradient-boosting model for any child of the TreeBooster class. More...

#include <GBModel.h>

Public Member Functions

 GBModel (std::string lt="MSE", int n_learners=200, double lr=0.1, double ss=0.25, int md=5, int ms=3, SplitAlg sa=HIST, ::std::string activation_func="", double weight_decay=0.0, double rl=1.0, double gamma=0.0, SubsampleFunction ssf=default_subsample)
 Overloaded default constructor.
 GBModel (::CNum::Model::Loss::LossProfile loss_profile, int n_learners, double lr, double ss, int md, int ms, SplitAlg sa, ::CNum::Model::Activation::ActivationFunc activation_func, double weight_decay, double rl, double gamma, SubsampleFunction ssf=default_subsample)
 Parameterized constructor.
 GBModel (const GBModel &other) noexcept
 Copy constructor.
GBModel< TreeType > & operator= (const GBModel &other) noexcept
 Copy assignment.
 GBModel (GBModel &&other) noexcept
 Move constructor.
GBModel< TreeType > & operator= (GBModel &&other) noexcept
 Move assignment.
 ~GBModel ()
 Destructor.
void fit (::CNum::DataStructs::Matrix< double > &X, ::CNum::DataStructs::Matrix< double > &y, bool verbose=true)
 Train the model.
::CNum::DataStructs::Matrix< double > predict (::CNum::DataStructs::Matrix< double > &data)
 Inference (making predictions).
void save_model (std::string path)
 Save Model to JSON encoded ".cmod" file.

Static Public Member Functions

static GBModel< TreeType > load_model (std::string path)
 Load Model from JSON encoded ".cmod" file.

Detailed Description

template<typename TreeType>
class CNum::Model::Tree::GBModel< TreeType >

A gradient-boosting model for any child of the TreeBooster class.

Template Parameters
TreeTypeA child of the TreeBooster class

The GBModel is a robust gradient-boosting model that can be used for both regression and classification on tabular data; simply set the loss and activation parameters of the constructor accordingly (see Loss and Activation classes) for available Loss and Activation functions.

Constructor & Destructor Documentation

◆ GBModel() [1/4]

template<typename TreeType>
CNum::Model::Tree::GBModel< TreeType >::GBModel ( std::string lt = "MSE",
int n_learners = 200,
double lr = 0.1,
double ss = 0.25,
int md = 5,
int ms = 3,
SplitAlg sa = HIST,
::std::string activation_func = "",
double weight_decay = 0.0,
double rl = 1.0,
double gamma = 0.0,
SubsampleFunction ssf = default_subsample )

Overloaded default constructor.

Parameters
ltLoss Type (the name of the loss function)
n_learnersThe number of TreeBooster learners to use
lrThe learning rate
ssThe amount of the dataset to sample for each tree
mdThe max depth of each tree
msThe minimum number of samples required to continue building a tree
saSplit Algorithm; The method used to find the best splits at each node (GREEDY or HIST)
activation_funcThe name of the activation function to apply after making predictions
weight_decayA threshold used to detirmine whether a split is worth considering
rlReg Lambda; A regularization parameter used in gain calculations
gammaA regularization parameter used in gain calculations
ssfThe function used to take subsamples of the data that a TreeBooster is trained on

In the tree building process a split is only taken if the sum of the hessians in the resultant data partitions are both greater than weight_decay.

See TreeBoosterNode to understand how the regularization parameters are used

◆ GBModel() [2/4]

template<typename TreeType>
CNum::Model::Tree::GBModel< TreeType >::GBModel ( ::CNum::Model::Loss::LossProfile loss_profile,
int n_learners,
double lr,
double ss,
int md,
int ms,
SplitAlg sa,
::CNum::Model::Activation::ActivationFunc activation_func,
double weight_decay,
double rl,
double gamma,
SubsampleFunction ssf = default_subsample )

Parameterized constructor.

Parameters
loss_profileThe LossProfile for the loss function
n_learnersThe number of TreeBooster learners to use
lrThe learning rate
ssThe amount of the dataset to sample for each tree
mdThe max depth of each tree
msThe minimum number of samples required to continue building a tree
saSplit Algorithm; The method used to find the best splits at each node (GREEDY or HIST)
activation_funcThe activation function to apply after making predictions
weight_decayA threshold used to detirmine whether a split is worth considering
rlReg Lambda; A regularization parameter used in gain calculations
gammaA regularization parameter used in gain calculations
ssfThe function used to take subsamples of the data that a TreeBooster is trained on

In the tree building process a split is only taken if the sum of the hessians in the resultant data partitions are both greater than weight_decay.

See TreeBoosterNode to understand how the regularization parameters are used

◆ GBModel() [3/4]

template<typename TreeType>
CNum::Model::Tree::GBModel< TreeType >::GBModel ( const GBModel< TreeType > & other)
noexcept

Copy constructor.

◆ GBModel() [4/4]

template<typename TreeType>
CNum::Model::Tree::GBModel< TreeType >::GBModel ( GBModel< TreeType > && other)
noexcept

Move constructor.

◆ ~GBModel()

template<typename TreeType>
CNum::Model::Tree::GBModel< TreeType >::~GBModel ( )

Destructor.

Member Function Documentation

◆ fit()

template<typename TreeType>
void CNum::Model::Tree::GBModel< TreeType >::fit ( ::CNum::DataStructs::Matrix< double > & X,
::CNum::DataStructs::Matrix< double > & y,
bool verbose = true )

Train the model.

Parameters
XThe tabular data used to train the GBModel
yThe labels for the data (the intended output of the model)

◆ load_model()

template<typename TreeType>
GBModel< TreeType > CNum::Model::Tree::GBModel< TreeType >::load_model ( std::string path)
static

Load Model from JSON encoded ".cmod" file.

Parameters
pathThe path to the ".cmod" file
Returns
The GBModel

◆ operator=() [1/2]

template<typename TreeType>
GBModel< TreeType > & CNum::Model::Tree::GBModel< TreeType >::operator= ( const GBModel< TreeType > & other)
noexcept

Copy assignment.

◆ operator=() [2/2]

template<typename TreeType>
GBModel< TreeType > & CNum::Model::Tree::GBModel< TreeType >::operator= ( GBModel< TreeType > && other)
noexcept

Move assignment.

◆ predict()

template<typename TreeType>
CNum::DataStructs::Matrix< double > CNum::Model::Tree::GBModel< TreeType >::predict ( ::CNum::DataStructs::Matrix< double > & data)

Inference (making predictions).

Parameters
Thedata to make predictions on
Returns
The predictions

◆ save_model()

template<typename TreeType>
void CNum::Model::Tree::GBModel< TreeType >::save_model ( std::string path)

Save Model to JSON encoded ".cmod" file.

Parameters
pathThe path to save the file to

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