ml_DTrees
import { ml_DTrees } from '@banou/opencv-wasm'Use after await initOpenCV(). See the initialization and named imports guide.
Native object: release it with using or delete(). Factories can return null; check before calling methods. Inherits ml_StatModel.
Decision Tree *
***************************************************************************************
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: ml_intro_trees
Constructors and members
static create
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).
create(): ml_DTrees | null;The ml_DTrees | null result.
static load
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
load(filepath: EmbindString, nodeName: EmbindString): ml_DTrees | null;2 available overloads
load(filepath: EmbindString): ml_DTrees | null;load(filepath: EmbindString, nodeName: EmbindString): ml_DTrees | null;filepathpath to serialized DTree
nodeNamename of node containing the classifier
The ml_DTrees | null result.
clone
Create another handle to the same native object. This retains the object without copying its pixels or algorithm state; dispose both handles separately.
clone(): this;The this result.
getMaxCategories
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: setMaxCategories
getMaxCategories(): number;The number result.
setMaxCategories
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: setMaxCategories See: getMaxCategories
setMaxCategories(val: number): void;valval argument (number).
getMaxDepth
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 ml_intro_trees "here"), and/or if the
tree is pruned. Default value is INT_MAX.
See: setMaxDepth
getMaxDepth(): number;The number result.
setMaxDepth
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 ml_intro_trees "here"), and/or if the
tree is pruned. Default value is INT_MAX.
See: setMaxDepth See: getMaxDepth
setMaxDepth(val: number): void;valval argument (number).
getMinSampleCount
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: setMinSampleCount
getMinSampleCount(): number;The number result.
setMinSampleCount
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: setMinSampleCount See: getMinSampleCount
setMinSampleCount(val: number): void;valval argument (number).
getCVFolds
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: setCVFolds
getCVFolds(): number;The number result.
setCVFolds
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: setCVFolds See: getCVFolds
setCVFolds(val: number): void;valval argument (number).
getUseSurrogates
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: setUseSurrogates
getUseSurrogates(): boolean;The boolean result.
setUseSurrogates
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: setUseSurrogates See: getUseSurrogates
setUseSurrogates(val: boolean): void;valval argument (boolean).
getUse1SERule
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: setUse1SERule
getUse1SERule(): boolean;The boolean result.
setUse1SERule
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: setUse1SERule See: getUse1SERule
setUse1SERule(val: boolean): void;valval argument (boolean).
getTruncatePrunedTree
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: setTruncatePrunedTree
getTruncatePrunedTree(): boolean;The boolean result.
setTruncatePrunedTree
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: setTruncatePrunedTree See: getTruncatePrunedTree
setTruncatePrunedTree(val: boolean): void;valval argument (boolean).
getRegressionAccuracy
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: setRegressionAccuracy
getRegressionAccuracy(): number;The number result.
setRegressionAccuracy
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: setRegressionAccuracy See: getRegressionAccuracy
setRegressionAccuracy(val: number): void;valval argument (number).
getPriors
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: setPriors
getPriors(): Mat;The Mat result. Release returned native handles with using or delete(), including handles nested in results.
setPriors
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: setPriors See: getPriors
setPriors(val: Mat): void;valval argument (Mat).
These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.