OpenCV
3.0.0
Open Source Computer Vision
|
The class represents a single decision tree or a collection of decision trees. More...
#include "ml.hpp"
Classes | |
class | Node |
The class represents a decision tree node. More... | |
class | Split |
The class represents split in a decision tree. More... | |
Public Types | |
enum | Flags { PREDICT_AUTO =0, PREDICT_SUM =(1<<8), PREDICT_MAX_VOTE =(2<<8), PREDICT_MASK =(3<<8) } |
Public Types inherited from cv::ml::StatModel | |
enum | Flags { UPDATE_MODEL = 1, RAW_OUTPUT =1, COMPRESSED_INPUT =2, PREPROCESSED_INPUT =4 } |
Public Member Functions | |
virtual int | getCVFolds () const =0 |
virtual int | getMaxCategories () const =0 |
virtual int | getMaxDepth () const =0 |
virtual int | getMinSampleCount () const =0 |
virtual const std::vector< Node > & | getNodes () const =0 |
Returns all the nodes. More... | |
virtual cv::Mat | getPriors () const =0 |
The array of a priori class probabilities, sorted by the class label value. More... | |
virtual float | getRegressionAccuracy () const =0 |
virtual const std::vector< int > & | getRoots () const =0 |
Returns indices of root nodes. More... | |
virtual const std::vector < Split > & | getSplits () const =0 |
Returns all the splits. More... | |
virtual const std::vector< int > & | getSubsets () const =0 |
Returns all the bitsets for categorical splits. More... | |
virtual bool | getTruncatePrunedTree () const =0 |
virtual bool | getUse1SERule () const =0 |
virtual bool | getUseSurrogates () const =0 |
virtual void | setCVFolds (int val)=0 |
virtual void | setMaxCategories (int val)=0 |
virtual void | setMaxDepth (int val)=0 |
virtual void | setMinSampleCount (int val)=0 |
virtual void | setPriors (const cv::Mat &val)=0 |
The array of a priori class probabilities, sorted by the class label value. More... | |
virtual void | setRegressionAccuracy (float val)=0 |
virtual void | setTruncatePrunedTree (bool val)=0 |
virtual void | setUse1SERule (bool val)=0 |
virtual void | setUseSurrogates (bool val)=0 |
Public Member Functions inherited from cv::ml::StatModel | |
virtual float | calcError (const Ptr< TrainData > &data, bool test, OutputArray resp) const |
Computes error on the training or test dataset. More... | |
virtual bool | empty () const |
Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read. More... | |
virtual int | getVarCount () const =0 |
Returns the number of variables in training samples. More... | |
virtual bool | isClassifier () const =0 |
Returns true if the model is classifier. More... | |
virtual bool | isTrained () const =0 |
Returns true if the model is trained. More... | |
virtual float | predict (InputArray samples, OutputArray results=noArray(), int flags=0) const =0 |
Predicts response(s) for the provided sample(s) More... | |
virtual bool | train (const Ptr< TrainData > &trainData, int flags=0) |
Trains the statistical model. More... | |
virtual bool | train (InputArray samples, int layout, InputArray responses) |
Trains the statistical model. More... | |
Public Member Functions inherited from cv::Algorithm | |
Algorithm () | |
virtual | ~Algorithm () |
virtual void | clear () |
Clears the algorithm state. More... | |
virtual String | getDefaultName () const |
virtual void | read (const FileNode &fn) |
Reads algorithm parameters from a file storage. More... | |
virtual void | save (const String &filename) const |
virtual void | write (FileStorage &fs) const |
Stores algorithm parameters in a file storage. More... | |
Static Public Member Functions | |
static Ptr< DTrees > | create () |
Creates the empty model. More... | |
Static Public Member Functions inherited from cv::ml::StatModel | |
template<typename _Tp > | |
static Ptr< _Tp > | train (const Ptr< TrainData > &data, int flags=0) |
Create and train model with default parameters. More... | |
Static Public Member Functions inherited from cv::Algorithm | |
template<typename _Tp > | |
static Ptr< _Tp > | load (const String &filename, const String &objname=String()) |
Loads algorithm from the file. More... | |
template<typename _Tp > | |
static Ptr< _Tp > | loadFromString (const String &strModel, const String &objname=String()) |
Loads algorithm from a String. More... | |
template<typename _Tp > | |
static Ptr< _Tp > | read (const FileNode &fn) |
Reads algorithm from the file node. More... | |
The class represents a single decision tree or a collection of decision trees.
The current public interface of the class allows user to train only a single decision tree, however the class is capable of storing multiple decision trees and using them for prediction (by summing responses or using a voting schemes), and the derived from DTrees classes (such as RTrees and Boost) use this capability to implement decision tree ensembles.
Creates the empty model.
The static method creates empty decision tree with the specified parameters. It should be then trained using train method (see StatModel::train). Alternatively, you can load the model from file using Algorithm::load<DTrees>(filename).
|
pure virtual |
If CVFolds > 1 then algorithms prunes the built decision tree using K-fold cross-validation procedure where K is equal to CVFolds. Default value is 10.
|
pure virtual |
Cluster possible values of a categorical variable into K<=maxCategories clusters to find a suboptimal split. If a discrete variable, on which the training procedure tries to make a split, takes more than maxCategories values, the precise best subset estimation may take a very long time because the algorithm is exponential. Instead, many decision trees engines (including our implementation) try to find sub-optimal split in this case by clustering all the samples into maxCategories clusters that is some categories are merged together. The clustering is applied only in n > 2-class classification problems for categorical variables with N > max_categories possible values. In case of regression and 2-class classification the optimal split can be found efficiently without employing clustering, thus the parameter is not used in these cases. Default value is 10.
|
pure virtual |
The maximum possible depth of the tree. That is the training algorithms attempts to split a node while its depth is less than maxDepth. The root node has zero depth. The actual depth may be smaller if the other termination criteria are met (see the outline of the training procedure here), and/or if the tree is pruned. Default value is INT_MAX.
|
pure virtual |
If the number of samples in a node is less than this parameter then the node will not be split.
Default value is 10.
|
pure virtual |
Returns all the nodes.
all the node indices are indices in the returned vector
|
pure virtual |
The array of a priori class probabilities, sorted by the class label value.
The parameter can be used to tune the decision tree preferences toward a certain class. For example, if you want to detect some rare anomaly occurrence, the training base will likely contain much more normal cases than anomalies, so a very good classification performance will be achieved just by considering every case as normal. To avoid this, the priors can be specified, where the anomaly probability is artificially increased (up to 0.5 or even greater), so the weight of the misclassified anomalies becomes much bigger, and the tree is adjusted properly.
You can also think about this parameter as weights of prediction categories which determine relative weights that you give to misclassification. That is, if the weight of the first category is 1 and the weight of the second category is 10, then each mistake in predicting the second category is equivalent to making 10 mistakes in predicting the first category. Default value is empty Mat.
|
pure virtual |
Termination criteria for regression trees. If all absolute differences between an estimated value in a node and values of train samples in this node are less than this parameter then the node will not be split further. Default value is 0.01f
|
pure virtual |
Returns indices of root nodes.
|
pure virtual |
Returns all the splits.
all the split indices are indices in the returned vector
|
pure virtual |
Returns all the bitsets for categorical splits.
Split::subsetOfs is an offset in the returned vector
|
pure virtual |
If true then pruned branches are physically removed from the tree. Otherwise they are retained and it is possible to get results from the original unpruned (or pruned less aggressively) tree. Default value is true.
|
pure virtual |
If true then a pruning will be harsher. This will make a tree more compact and more resistant to the training data noise but a bit less accurate. Default value is true.
|
pure virtual |
If true then surrogate splits will be built. These splits allow to work with missing data and compute variable importance correctly. Default value is false.
|
pure virtual |
|
pure virtual |
|
pure virtual |
|
pure virtual |
|
pure virtual |
The array of a priori class probabilities, sorted by the class label value.
|
pure virtual |
|
pure virtual |
|
pure virtual |
|
pure virtual |