This class implements the Classification And Regression Trees algorithm by Breiman et al for decision tree learning. A CART tree is a binary decision tree that is constructed by splitting a node into two child nodes repeatedly, beginning with the root node that contains the whole dataset.
TREE GROWING PROCESS :
During the tree growing process, we recursively split a node into left child and right child so that the resulting nodes are "purest". We do this until any of the stopping criteria is met. To find the best split, we scan through all possible splits in all predictive attributes. The best split is one that maximises some splitting criterion. For classification tasks, ie. when the dependent attribute is categorical, the Gini index is used. For regression tasks, ie. when the dependent variable is continuous, least squares deviation is used. The algorithm uses two stopping criteria : if node becomes completely "pure", ie. all its members have identical dependent variable, or all of them have identical predictive attributes (independent variables).
.
COST-COMPLEXITY PRUNING :
The maximal tree, \(T_max\) grown during tree growing process is bound to overfit. Hence pruning becomes necessary. Cost-Complexity pruning yields a list of subtrees of varying depths using the complexity normalized resubstitution error, \(R_\alpha(T)\). The resubstitution error R(T) is a measure of how well a decision tree fits the training data. This measure favours larger trees over smaller ones. However, complexity normalized resubstitution error, adds penalty for increased complexity and hence counters overfitting.
\(R_\alpha(T)=R(T)+\alpha \times (numleaves)\)
The best subtree among the list of subtrees can be chosen using cross validation or using best-fit in the test dataset.
cf. https://onlinecourses.science.psu.edu/stat557/node/93
HANDLING MISSING VALUES :
While choosing the best split at a node, missing attribute values are left out. But data vectors with missing values of the best attribute chosen are sent to left child or right child using a surrogate split. A surrogate split is one that imitates the best split as closely as possible. While choosing a surrogate split, all splits alternative to the best split are scaned and the degree of closeness between the two is measured using a metric called predictive measure of association, \(\lambda_{i,j}\).
\(\lambda_{i,j} = \frac{min(P_L,P_R)-(1-P_{L_iL_j}-P_{R_iR_j})}{min(P_L,P_R)}\)
where \(P_L\) and \(P_R\) are the node probabilities for the optimal split of node i into left and right nodes respectively, \(P_{L_iL_j}\) ( \(P_{R_iR_j}\) resp.) is the probability that both (optimal) node i and (surrogate) node j send an observation to the Left (Right resp.).
We use best surrogate split, 2nd best surrogate split and so on until all data points with missing attributes in a node have been sent to left/right child. If all possible surrogate splits are used up but some data points are still to be assigned left/right child, majority rule is used, ie. the data points are assigned the child where majority of data points have gone from the node.
cf. http://pic.dhe.ibm.com/infocenter/spssstat/v20r0m0/index.jsp?topic=%2Fcom.ibm.spss.statistics.help%2Falg_tree-cart.htm
Public 类型 | |
typedef CTreeMachineNode < CARTreeNodeData > | node_t |
typedef CBinaryTreeMachineNode < CARTreeNodeData > | bnode_t |
Public 属性 | |
SGIO * | io |
Parallel * | parallel |
Version * | version |
Parameter * | m_parameters |
Parameter * | m_model_selection_parameters |
Parameter * | m_gradient_parameters |
uint32_t | m_hash |
静态 Public 属性 | |
static const float64_t | MISSING =CMath::MAX_REAL_NUMBER |
static const float64_t | MIN_SPLIT_GAIN =1e-7 |
static const float64_t | EQ_DELTA =1e-7 |
Protected 属性 | |
float64_t | m_label_epsilon |
SGVector< bool > | m_nominal |
SGVector< float64_t > | m_weights |
bool | m_types_set |
bool | m_weights_set |
bool | m_apply_cv_pruning |
int32_t | m_folds |
EProblemType | m_mode |
CDynamicArray< float64_t > * | m_alphas |
int32_t | m_max_depth |
int32_t | m_min_node_size |
CTreeMachineNode < CARTreeNodeData > * | m_root |
CDynamicObjectArray * | m_machines |
float64_t | m_max_train_time |
CLabels * | m_labels |
ESolverType | m_solver_type |
bool | m_store_model_features |
bool | m_data_locked |
|
inherited |
bnode_t type- Tree node with max 2 possible children
在文件 TreeMachine.h 第 55 行定义.
|
inherited |
node_t type- Tree node with many possible children
在文件 TreeMachine.h 第 52 行定义.
CCARTree | ( | ) |
default constructor
在文件 CARTree.cpp 第 40 行定义.
CCARTree | ( | SGVector< bool > | attribute_types, |
EProblemType | prob_type = PT_MULTICLASS |
||
) |
constructor
attribute_types | type of each predictive attribute (true for nominal, false for ordinal/continuous) |
prob_type | machine problem type - PT_MULTICLASS or PT_REGRESSION |
在文件 CARTree.cpp 第 46 行定义.
CCARTree | ( | SGVector< bool > | attribute_types, |
EProblemType | prob_type, | ||
int32_t | num_folds, | ||
bool | cv_prune | ||
) |
constructor - to be used while using cross-validation pruning
attribute_types | type of each predictive attribute (true for nominal, false for ordinal/continuous) |
prob_type | machine problem type - PT_MULTICLASS or PT_REGRESSION |
num_folds | number of subsets used in cross-valiation |
cv_prune | - whether to use cross-validation pruning |
在文件 CARTree.cpp 第 54 行定义.
|
virtual |
destructor
在文件 CARTree.cpp 第 65 行定义.
apply machine to data if data is not specified apply to the current features
data | (test)data to be classified |
在文件 Machine.cpp 第 152 行定义.
|
virtualinherited |
apply machine to data in means of binary classification problem
被 CKernelMachine, COnlineLinearMachine, CWDSVMOcas, CNeuralNetwork, CLinearMachine, CGaussianProcessClassification, CDomainAdaptationSVMLinear, CDomainAdaptationSVM, CPluginEstimate , 以及 CBaggingMachine 重载.
在文件 Machine.cpp 第 208 行定义.
|
protected |
uses current subtree to classify/regress data
feats | data to be classified/regressed |
current | root of current subtree |
在文件 CARTree.cpp 第 976 行定义.
|
virtualinherited |
apply machine to data in means of latent problem
被 CLinearLatentMachine 重载.
在文件 Machine.cpp 第 232 行定义.
Applies a locked machine on a set of indices. Error if machine is not locked
indices | index vector (of locked features) that is predicted |
在文件 Machine.cpp 第 187 行定义.
|
virtualinherited |
applies a locked machine on a set of indices for binary problems
被 CKernelMachine , 以及 CMultitaskLinearMachine 重载.
在文件 Machine.cpp 第 238 行定义.
|
virtualinherited |
applies a locked machine on a set of indices for latent problems
在文件 Machine.cpp 第 266 行定义.
|
virtualinherited |
applies a locked machine on a set of indices for multiclass problems
在文件 Machine.cpp 第 252 行定义.
|
virtualinherited |
applies a locked machine on a set of indices for regression problems
被 CKernelMachine 重载.
在文件 Machine.cpp 第 245 行定义.
|
virtualinherited |
applies a locked machine on a set of indices for structured problems
在文件 Machine.cpp 第 259 行定义.
|
virtual |
classify data using Classification Tree
data | data to be classified |
重载 CMachine .
在文件 CARTree.cpp 第 99 行定义.
|
virtualinherited |
applies to one vector
被 CKernelMachine, CRelaxedTree, CWDSVMOcas, COnlineLinearMachine, CLinearMachine, CMultitaskLinearMachine, CMulticlassMachine, CKNN, CDistanceMachine, CMultitaskLogisticRegression, CMultitaskLeastSquaresRegression, CScatterSVM, CGaussianNaiveBayes, CPluginEstimate , 以及 CFeatureBlockLogisticRegression 重载.
|
virtual |
Get regression labels using Regression Tree
data | data whose regression output is needed |
重载 CMachine .
在文件 CARTree.cpp 第 111 行定义.
|
virtualinherited |
apply machine to data in means of SO classification problem
被 CLinearStructuredOutputMachine 重载.
在文件 Machine.cpp 第 226 行定义.
|
inherited |
Builds a dictionary of all parameters in SGObject as well of those of SGObjects that are parameters of this object. Dictionary maps parameters to the objects that own them.
dict | dictionary of parameters to be built. |
在文件 SGObject.cpp 第 597 行定义.
|
protectedvirtual |
CARTtrain - recursive CART training method
data | training data |
weights | vector of weights of data points |
labels | labels of data points |
level | current tree depth |
在文件 CARTree.cpp 第 285 行定义.
void clear_feature_types | ( | ) |
clear feature types of various features
在文件 CARTree.cpp 第 197 行定义.
void clear_weights | ( | ) |
clear weights of data points
在文件 CARTree.cpp 第 180 行定义.
|
virtualinherited |
Creates a clone of the current object. This is done via recursively traversing all parameters, which corresponds to a deep copy. Calling equals on the cloned object always returns true although none of the memory of both objects overlaps.
在文件 SGObject.cpp 第 714 行定义.
|
inherited |
|
protectedvirtual |
computes best attribute for CARTtrain
mat | data matrix |
weights | data weights |
labels_vec | data labels |
left | stores feature values for left transition |
right | stores feature values for right transition |
is_left_final | stores which feature vectors go to the left child |
num_missing | number of missing attributes |
count_left | stores number of feature values for left transition |
count_right | stores number of feature values for right transition |
被 CRandomCARTree 重载.
在文件 CARTree.cpp 第 486 行定义.
|
protected |
computes error in classification/regression for classification it eveluates weight_missclassified/total_weight for regression it evaluates weighted sum of squared error/total_weight
labels | the labels whose error needs to be calculated |
reference | actual labels against which test labels are compared |
weights | weights associated with the labels |
在文件 CARTree.cpp 第 1198 行定义.
recursively cuts weakest link(s) in a tree
node | the root of subtree whose weakest link it cuts |
alpha | alpha value corresponding to weakest link |
在文件 CARTree.cpp 第 1305 行定义.
Locks the machine on given labels and data. After this call, only train_locked and apply_locked may be called
Only possible if supports_locking() returns true
labs | labels used for locking |
features | features used for locking |
被 CKernelMachine 重载.
在文件 Machine.cpp 第 112 行定义.
|
virtualinherited |
Unlocks a locked machine and restores previous state
被 CKernelMachine 重载.
在文件 Machine.cpp 第 143 行定义.
|
virtualinherited |
A deep copy. All the instance variables will also be copied.
在文件 SGObject.cpp 第 198 行定义.
Recursively compares the current SGObject to another one. Compares all registered numerical parameters, recursion upon complex (SGObject) parameters. Does not compare pointers!
May be overwritten but please do with care! Should not be necessary in most cases.
other | object to compare with |
accuracy | accuracy to use for comparison (optional) |
tolerant | allows linient check on float equality (within accuracy) |
在文件 SGObject.cpp 第 618 行定义.
recursively finds alpha corresponding to weakest link(s)
node | the root of subtree whose weakest link it finds |
在文件 CARTree.cpp 第 1284 行定义.
|
protected |
recursively forms base case $ft_1$f tree from $ft_max$f during pruning
node | the root of current subtree |
在文件 CARTree.cpp 第 1335 行定义.
|
protected |
returns gain in regression case
wleft | left child weight distribution |
wright | right child weights distribution |
wtotal | weight distribution in current node |
labels | regression labels |
在文件 CARTree.cpp 第 918 行定义.
|
protected |
returns gain in Gini impurity measure
wleft | left child label distribution |
wright | right child label distribution |
wtotal | label distribution in current node |
在文件 CARTree.cpp 第 932 行定义.
|
virtualinherited |
get classifier type
被 CLaRank, CSVMLight, CDualLibQPBMSOSVM, CNeuralNetwork, CCCSOSVM, CLeastAngleRegression, CLDA, CKernelRidgeRegression, CLibLinearMTL, CBaggingMachine, CLibLinear, CGaussianProcessClassification, CKMeans, CLibSVR, CQDA, CGaussianNaiveBayes, CSVRLight, CMCLDA, CLinearRidgeRegression, CKNN, CScatterSVM, CGaussianProcessRegression, CSGDQN, CSVMSGD, CSVMOcas, COnlineSVMSGD, CLeastSquaresRegression, CMKLRegression, CDomainAdaptationSVMLinear, CMKLMulticlass, CWDSVMOcas, CHierarchical, CMKLOneClass, CLibSVM, CStochasticSOSVM, CMKLClassification, CDomainAdaptationSVM, CLPBoost, CPerceptron, CAveragedPerceptron, CFWSOSVM, CNewtonSVM, CLPM, CGMNPSVM, CSVMLightOneClass, CSVMLin, CMulticlassLibSVM, CLibSVMOneClass, CMPDSVM, CGPBTSVM, CGNPPSVM , 以及 CCPLEXSVM 重载.
在文件 Machine.cpp 第 92 行定义.
SGVector< bool > get_feature_types | ( | ) | const |
set feature types of various features
在文件 CARTree.cpp 第 192 行定义.
|
inherited |
|
inherited |
|
inherited |
float64_t get_label_epsilon | ( | ) |
|
virtualinherited |
|
virtual |
get problem type - multiclass classification or regression
int32_t get_max_depth | ( | ) | const |
|
inherited |
int32_t get_min_node_size | ( | ) | const |
|
inherited |
在文件 SGObject.cpp 第 498 行定义.
|
inherited |
Returns description of a given parameter string, if it exists. SG_ERROR otherwise
param_name | name of the parameter |
在文件 SGObject.cpp 第 522 行定义.
|
inherited |
Returns index of model selection parameter with provided index
param_name | name of model selection parameter |
在文件 SGObject.cpp 第 535 行定义.
|
virtual |
int32_t get_num_folds | ( | ) | const |
get number of subsets used for cross validation
在文件 CARTree.cpp 第 203 行定义.
|
inherited |
|
inherited |
|
inherited |
|
protected |
modify labels for compute_best_attribute
labels_vec | labels vector |
n_ulabels | stores number of unique labels |
在文件 CARTree.cpp 第 462 行定义.
|
protected |
returns Gini impurity of a node
weighted_lab_classes | vector of weights associated with various labels |
total_weight | stores the total weight of all classes |
在文件 CARTree.cpp 第 944 行定义.
|
protected |
handles missing values for a chosen continuous surrogate attribute
m | training data matrix |
missing_vecs | column indices of vectors with missing attribute in data matrix |
association_index | stores the final lambda values used to address members of missing_vecs |
intersect_vecs | column indices of vectors with known values for the best attribute as well as the chosen surrogate |
is_left | whether a vector goes into left child |
weights | weights of training data vectors |
p | min(p_l,p_r) in the lambda formula |
attr | surrogate attribute chosen for split |
在文件 CARTree.cpp 第 781 行定义.
|
protected |
handles missing values for a chosen nominal surrogate attribute
m | training data matrix |
missing_vecs | column indices of vectors with missing attribute in data matrix |
association_index | stores the final lambda values used to address members of missing_vecs |
intersect_vecs | column indices of vectors with known values for the best attribute as well as the chosen surrogate |
is_left | whether a vector goes into left child |
weights | weights of training data vectors |
p | min(p_l,p_r) in the lambda formula |
attr | surrogate attribute chosen for split |
在文件 CARTree.cpp 第 838 行定义.
|
protected |
initializes members of class
在文件 CARTree.cpp 第 1361 行定义.
|
virtualinherited |
If the SGSerializable is a class template then TRUE will be returned and GENERIC is set to the type of the generic.
generic | set to the type of the generic if returning TRUE |
在文件 SGObject.cpp 第 296 行定义.
|
virtual |
whether labels supplied are valid for current problem type
lab | labels supplied |
在文件 CARTree.cpp 第 89 行定义.
|
protected |
returns least squares deviation
labels | regression labels |
weights | weights of regression data points |
total_weight | stores sum of weights in weights vector |
在文件 CARTree.cpp 第 958 行定义.
|
virtualinherited |
Load this object from file. If it will fail (returning FALSE) then this object will contain inconsistent data and should not be used!
file | where to load from |
prefix | prefix for members |
在文件 SGObject.cpp 第 369 行定义.
|
protectedvirtualinherited |
Can (optionally) be overridden to post-initialize some member variables which are not PARAMETER::ADD'ed. Make sure that at first the overridden method BASE_CLASS::LOAD_SERIALIZABLE_POST is called.
ShogunException | will be thrown if an error occurs. |
被 CKernel, CWeightedDegreePositionStringKernel, CList, CAlphabet, CLinearHMM, CGaussianKernel, CInverseMultiQuadricKernel, CCircularKernel , 以及 CExponentialKernel 重载.
在文件 SGObject.cpp 第 426 行定义.
|
protectedvirtualinherited |
Can (optionally) be overridden to pre-initialize some member variables which are not PARAMETER::ADD'ed. Make sure that at first the overridden method BASE_CLASS::LOAD_SERIALIZABLE_PRE is called.
ShogunException | will be thrown if an error occurs. |
被 CDynamicArray< T >, CDynamicArray< float64_t >, CDynamicArray< float32_t >, CDynamicArray< int32_t >, CDynamicArray< char >, CDynamicArray< bool > , 以及 CDynamicObjectArray 重载.
在文件 SGObject.cpp 第 421 行定义.
|
virtualinherited |
在文件 SGObject.cpp 第 262 行定义.
|
inherited |
prints all parameter registered for model selection and their type
在文件 SGObject.cpp 第 474 行定义.
|
virtualinherited |
|
protected |
prune by cross validation
data | training data |
folds | the integer V for V-fold cross validation |
在文件 CARTree.cpp 第 1059 行定义.
|
protected |
cost-complexity pruning
tree | the tree to be pruned |
在文件 CARTree.cpp 第 1236 行定义.
void prune_using_test_dataset | ( | CDenseFeatures< float64_t > * | feats, |
CLabels * | gnd_truth, | ||
SGVector< float64_t > | weights = SGVector<float64_t>() |
||
) |
uses test dataset to choose best pruned subtree
feats | test data to be used |
gnd_truth | test labels |
weights | weights of data points |
在文件 CARTree.cpp 第 123 行定义.
|
virtualinherited |
Save this object to file.
file | where to save the object; will be closed during returning if PREFIX is an empty string. |
prefix | prefix for members |
在文件 SGObject.cpp 第 314 行定义.
|
protectedvirtualinherited |
Can (optionally) be overridden to post-initialize some member variables which are not PARAMETER::ADD'ed. Make sure that at first the overridden method BASE_CLASS::SAVE_SERIALIZABLE_POST is called.
ShogunException | will be thrown if an error occurs. |
被 CKernel 重载.
在文件 SGObject.cpp 第 436 行定义.
|
protectedvirtualinherited |
Can (optionally) be overridden to pre-initialize some member variables which are not PARAMETER::ADD'ed. Make sure that at first the overridden method BASE_CLASS::SAVE_SERIALIZABLE_PRE is called.
ShogunException | will be thrown if an error occurs. |
被 CKernel, CDynamicArray< T >, CDynamicArray< float64_t >, CDynamicArray< float32_t >, CDynamicArray< int32_t >, CDynamicArray< char >, CDynamicArray< bool > , 以及 CDynamicObjectArray 重载.
在文件 SGObject.cpp 第 431 行定义.
void set_feature_types | ( | SGVector< bool > | ft | ) |
set feature types of various features
ft | bool vector true for nominal feature false for continuous feature type |
在文件 CARTree.cpp 第 186 行定义.
|
inherited |
在文件 SGObject.cpp 第 41 行定义.
|
inherited |
在文件 SGObject.cpp 第 46 行定义.
|
inherited |
在文件 SGObject.cpp 第 51 行定义.
|
inherited |
在文件 SGObject.cpp 第 56 行定义.
|
inherited |
在文件 SGObject.cpp 第 61 行定义.
|
inherited |
在文件 SGObject.cpp 第 66 行定义.
|
inherited |
在文件 SGObject.cpp 第 71 行定义.
|
inherited |
在文件 SGObject.cpp 第 76 行定义.
|
inherited |
在文件 SGObject.cpp 第 81 行定义.
|
inherited |
在文件 SGObject.cpp 第 86 行定义.
|
inherited |
在文件 SGObject.cpp 第 91 行定义.
|
inherited |
在文件 SGObject.cpp 第 96 行定义.
|
inherited |
在文件 SGObject.cpp 第 101 行定义.
|
inherited |
在文件 SGObject.cpp 第 106 行定义.
|
inherited |
在文件 SGObject.cpp 第 111 行定义.
|
inherited |
set generic type to T
|
inherited |
|
inherited |
|
inherited |
void set_label_epsilon | ( | float64_t | epsilon | ) |
|
virtual |
set labels - automagically switch machine problem type based on type of labels supplied
lab | labels |
重载 CMachine .
在文件 CARTree.cpp 第 70 行定义.
void set_machine_problem_type | ( | EProblemType | mode | ) |
set problem type - multiclass classification or regression
mode | EProblemType PT_MULTICLASS or PT_REGRESSION |
在文件 CARTree.cpp 第 84 行定义.
void set_max_depth | ( | int32_t | depth | ) |
|
inherited |
void set_min_node_size | ( | int32_t | nsize | ) |
void set_num_folds | ( | int32_t | folds | ) |
set number of subsets for cross validation
folds | number of folds used in cross validation |
在文件 CARTree.cpp 第 208 行定义.
|
inherited |
|
inherited |
|
virtualinherited |
Setter for store-model-features-after-training flag
store_model | whether model should be stored after training |
在文件 Machine.cpp 第 107 行定义.
|
virtualinherited |
A shallow copy. All the SGObject instance variables will be simply assigned and SG_REF-ed.
被 CGaussianKernel 重载.
在文件 SGObject.cpp 第 192 行定义.
|
protectedvirtualinherited |
enable unlocked cross-validation - no model features to store
重载 CMachine .
在文件 TreeMachine.h 第 152 行定义.
|
virtualinherited |
被 CKernelMachine , 以及 CMultitaskLinearMachine 重载.
|
protected |
handles missing values through surrogate splits
data | training data matrix |
weights | vector of weights of data points |
nm_left | whether a data point is put into left child (available for only data points with non-missing attribute attr) |
attr | best attribute chosen for split |
在文件 CARTree.cpp 第 706 行定义.
|
virtualinherited |
train machine
data | training data (parameter can be avoided if distance or kernel-based classifiers are used and distance/kernels are initialized with train data). If flag is set, model features will be stored after training. |
被 CRelaxedTree, CAutoencoder, CSGDQN , 以及 COnlineSVMSGD 重载.
在文件 Machine.cpp 第 39 行定义.
Trains a locked machine on a set of indices. Error if machine is not locked
NOT IMPLEMENTED
indices | index vector (of locked features) that is used for training |
被 CKernelMachine , 以及 CMultitaskLinearMachine 重载.
|
protectedvirtual |
train machine - build CART from training data
data | training data |
重载 CMachine .
在文件 CARTree.cpp 第 242 行定义.
|
protectedvirtualinherited |
returns whether machine require labels for training
被 COnlineLinearMachine, CHierarchical, CLinearLatentMachine, CVwConditionalProbabilityTree, CConditionalProbabilityTree , 以及 CLibSVMOneClass 重载.
|
inherited |
unset generic type
this has to be called in classes specializing a template class
在文件 SGObject.cpp 第 303 行定义.
|
virtualinherited |
Updates the hash of current parameter combination
在文件 SGObject.cpp 第 248 行定义.
|
inherited |
io
在文件 SGObject.h 第 369 行定义.
|
protected |
|
protected |
|
inherited |
parameters wrt which we can compute gradients
在文件 SGObject.h 第 384 行定义.
|
inherited |
Hash of parameter values
在文件 SGObject.h 第 387 行定义.
|
protectedinherited |
machines
在文件 BaseMulticlassMachine.h 第 56 行定义.
|
protected |
|
protected |
|
inherited |
model selection parameters
在文件 SGObject.h 第 381 行定义.
|
protected |
|
inherited |
parameters
在文件 SGObject.h 第 378 行定义.
|
protectedinherited |
tree root
在文件 TreeMachine.h 第 156 行定义.
|
protectedinherited |
|
protectedinherited |
|
protected |
|
protected |
|
static |
|
static |
|
inherited |
parallel
在文件 SGObject.h 第 372 行定义.
|
inherited |
version
在文件 SGObject.h 第 375 行定义.