Class cv::ml::DTrees#
The class represents a single decision tree or a collection of decision trees. View details
#include <opencv2/ml.hpp>Collaboration diagram for cv::ml::DTrees:
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
Return |
Name |
Description |
|---|---|---|
Public Member Functions#
Public Member Functions inherited from cv::ml::StatModel
Return |
Name |
Description |
|---|---|---|
|
|
Computes error on the training or test dataset. |
|
Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read. |
|
|
Returns the number of variables in training samples. |
|
|
Returns true if the model is classifier. |
|
|
Returns true if the model is trained. |
|
|
|
Predicts response(s) for the provided sample(s) |
|
Trains the statistical model. |
|
|
|
Trains the statistical model. |
Public Member Functions inherited from cv::Algorithm
Return |
Name |
Description |
|---|---|---|
|
Clears the algorithm state. |
|
|
Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read. |
|
|
Reads algorithm parameters from a file storage. |
|
|
||
|
|
|
|
Stores algorithm parameters in a file storage. |
|
|
Static Public Member Functions#
Static Public Member Functions inherited from cv::ml::StatModel
Return |
Name |
Description |
|---|---|---|
|
Create and train model with default parameters. |
Static Public Member Functions inherited from cv::Algorithm
Return |
Name |
Description |
|---|---|---|
|
|
Loads algorithm from the file. |
|
|
Loads algorithm from a String. |
|
Reads algorithm from the file node. |
Additional Inherited Members#
Protected Member Functions inherited from cv::Algorithm
Return |
Name |
Description |
|---|---|---|
|
Detailed Description#
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.
See also
ml_intro_trees
Member Enumeration Documentation#
enum Flags
|
|
|
|
Member Function Documentation#
getCVFolds()#
int cv::ml::DTrees::getCVFolds()
Python:
cv.ml.DTrees.getCVFolds() -> retval
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.
See also
getMaxCategories()#
int cv::ml::DTrees::getMaxCategories()
Python:
cv.ml.DTrees.getMaxCategories() -> retval
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.
See also
getMaxDepth()#
int cv::ml::DTrees::getMaxDepth()
Python:
cv.ml.DTrees.getMaxDepth() -> retval
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.
See also
getMinSampleCount()#
int cv::ml::DTrees::getMinSampleCount()
Python:
cv.ml.DTrees.getMinSampleCount() -> retval
If the number of samples in a node is less than this parameter then the node will not be split.
Default value is 10.
See also
getNodes()#
const std::vector< Node > & cv::ml::DTrees::getNodes()
Returns all the nodes.
all the node indices are indices in the returned vector
getPriors()#
cv::Mat cv::ml::DTrees::getPriors()
Python:
cv.ml.DTrees.getPriors() -> retval
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.
See also
getRegressionAccuracy()#
float cv::ml::DTrees::getRegressionAccuracy()
Python:
cv.ml.DTrees.getRegressionAccuracy() -> retval
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
See also
getRoots()#
const std::vector< int > & cv::ml::DTrees::getRoots()
Returns indices of root nodes.
getSplits()#
const std::vector< Split > & cv::ml::DTrees::getSplits()
Returns all the splits.
all the split indices are indices in the returned vector
getSubsets()#
const std::vector< int > & cv::ml::DTrees::getSubsets()
Returns all the bitsets for categorical splits.
Split::subsetOfs is an offset in the returned vector
getTruncatePrunedTree()#
bool cv::ml::DTrees::getTruncatePrunedTree()
Python:
cv.ml.DTrees.getTruncatePrunedTree() -> retval
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.
See also
getUse1SERule()#
bool cv::ml::DTrees::getUse1SERule()
Python:
cv.ml.DTrees.getUse1SERule() -> retval
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.
See also
getUseSurrogates()#
bool cv::ml::DTrees::getUseSurrogates()
Python:
cv.ml.DTrees.getUseSurrogates() -> retval
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.
Note
currently it’s not implemented.
See also
setCVFolds()#
void cv::ml::DTrees::setCVFolds(int val)
Python:
cv.ml.DTrees.setCVFolds(val)
See also
setMaxCategories()#
void cv::ml::DTrees::setMaxCategories(int val)
Python:
cv.ml.DTrees.setMaxCategories(val)
See also
setMaxDepth()#
void cv::ml::DTrees::setMaxDepth(int val)
Python:
cv.ml.DTrees.setMaxDepth(val)
See also
setMinSampleCount()#
void cv::ml::DTrees::setMinSampleCount(int val)
Python:
cv.ml.DTrees.setMinSampleCount(val)
See also
setPriors()#
void cv::ml::DTrees::setPriors(const cv::Mat & val)
Python:
cv.ml.DTrees.setPriors(val)
The array of a priori class probabilities, sorted by the class label value.
See also
setRegressionAccuracy()#
void cv::ml::DTrees::setRegressionAccuracy(float val)
Python:
cv.ml.DTrees.setRegressionAccuracy(val)
See also
setTruncatePrunedTree()#
void cv::ml::DTrees::setTruncatePrunedTree(bool val)
Python:
cv.ml.DTrees.setTruncatePrunedTree(val)
See also
setUse1SERule()#
void cv::ml::DTrees::setUse1SERule(bool val)
Python:
cv.ml.DTrees.setUse1SERule(val)
See also
setUseSurrogates()#
void cv::ml::DTrees::setUseSurrogates(bool val)
Python:
cv.ml.DTrees.setUseSurrogates(val)
See also
create()#
static Ptr< DTrees > cv::ml::DTrees::create()
Python:
cv.ml.DTrees.create() -> retval
cv.ml.DTrees_create() -> retval
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).
load()#
static Ptr< DTrees > cv::ml::DTrees::load(
const String & filepath,
const String & nodeName = String() )
Python:
cv.ml.DTrees.load(filepath[, nodeName]) -> retval
cv.ml.DTrees_load(filepath[, nodeName]) -> retval
Loads and creates a serialized DTrees from a file.
Use DTree::save to serialize and store an DTree to disk. Load the DTree from this file again, by calling this function with the path to the file. Optionally specify the node for the file containing the classifier
Parameters
filepath— path to serialized DTreenodeName— name of node containing the classifier
Source file#
The documentation for this class was generated from the following file:
opencv2/ml.hpp