RTrees class
The class implements the random forest predictor. https://docs.opencv.org/4.x/d0/d65/classcv_1_1ml_1_1RTrees.html
- Inheritance
- Available extensions
Constructors
- RTrees.create()
-
Creates an empty model. Use one of the train methods to train it, or RTrees.load.
factory
- RTrees.fromPointer(RTreesPtr ptr, [bool attach = true])
-
factory
- RTrees.load(String filepath)
-
Loads a model saved with save from
filepath. Throws CvException when the file does not hold a valid model.factory - RTrees.loadFromString(String strModel, {String objname = ''})
-
Loads a model from the content of a file saved with save (e.g. a Flutter asset).
factory
Properties
- activeVarCount ↔ int
-
The size of the randomly selected subset of features at each tree node.
getter/setter pair
- calculateVarImportance ↔ bool
-
If true then variable importance will be calculated.
getter/setter pair
- cvFolds ↔ int
-
The number of cross-validation folds used to prune the tree. OpenCV 4.x does not implement the
pruning: values > 1 throw and 1 is stored as 0 (no pruning).
getter/setter pair
- defaultName → String
-
The name used when saving the model,
opencv_ml_rtrees.no setter - hashCode → int
-
The hash code for this object.
no setterinherited
- isClassifier → bool
-
Whether the model is a classifier (false for a regressor).
no setter
- isDisposed → bool
-
Whether this object has been disposed.
no setterinherited
- isEmpty → bool
-
no setter
- isTrained → bool
-
no setter
- maxCategories ↔ int
-
Cluster possible values of a categorical variable into K <= maxCategories clusters to find a
suboptimal split. Must be >= 2, values above 15 are clamped to 15.
getter/setter pair
- maxDepth ↔ int
-
The maximum possible depth of the tree, values above 25 are clamped to 25.
getter/setter pair
- minSampleCount ↔ int
-
If the number of samples in a node is less than this parameter then the node will not be split.
getter/setter pair
-
nodes
→ List<
DTreesNode> -
All the nodes of the trees, the children of a node are referenced by index.
no setter
- oobError → double
-
The out-of-bag error of the trained forest, only computed when calculateVarImportance is
set or termCriteria has an epsilon; 0 otherwise.
no setter
- priors ↔ Mat
-
The array of a priori class probabilities, sorted by the class label value.
getter/setter pair
-
props
→ List<
Object?> -
no setterinherited
-
ptr
↔ Pointer<
RTrees> -
getter/setter pairinherited
- ref → RTrees
-
A view of the native memory behind ptr, not a copy.
no setteroverride
- regressionAccuracy ↔ double
-
Termination criteria for regression trees.
getter/setter pair
-
roots
→ List<
int> -
The indices of the root nodes, one per tree.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
splits
→ List<
DTreesSplit> -
All the splits of the trees, referenced by DTreesNode.split and DTreesSplit.next.
no setter
-
subsets
→ List<
int> -
The bitsets of the splits on categorical variables, see DTreesSplit.subsetOfs.
no setter
- termCriteria ↔ TermCriteria
-
Termination criteria of the training algorithm.
getter/setter pair
- truncatePrunedTree ↔ bool
-
If true then pruned branches are physically removed from the tree.
getter/setter pair
- use1SERule ↔ bool
-
If true then a pruning will be harsher.
getter/setter pair
- useSurrogates ↔ bool
-
Whether to build surrogate splits. Not implemented in OpenCV 4.x: training with
truethrows.getter/setter pair - varCount → int
-
Number of variables in training samples.
no setter
- varImportance → Mat
-
The variable importance array, empty unless calculateVarImportance was set when training.
no setter
Methods
-
calcError(
TrainData data, bool test) → (double, Mat) -
Computes the error on the training (
testfalse) or test (testtrue) part ofdata. -
calcErrorAsync(
TrainData data, bool test) → Future< (double, Mat)> -
Available on RTrees, provided by the RTreesAsync extension
-
clear(
) → void -
Calls OpenCV's
clear, which does not reset this model: it stays trained. Create a new model to start over. -
dispose(
) → void -
Releases the underlying native resources. Idempotent: calling it more
than once is safe, but the object must not be used after dispose.
inherited
-
freeNative(
) → void -
Frees the native resources owned by this object. Subclasses implement the
concrete free logic here; callers must use dispose instead.
override
-
getVotes(
Mat samples, {int flags = 0}) → Mat - Returns the result of each individual tree in the forest.
-
getVotesAsync(
Mat samples, {int flags = 0}) → Future< Mat> -
Available on RTrees, provided by the RTreesAsync extension
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
predict(
Mat samples, {int flags = 0}) → Mat -
Predicts the response for each row of
samples, one row of the returned Mat per sample. -
predictAsync(
Mat samples, {int flags = 0}) → Future< Mat> -
Available on RTrees, provided by the RTreesAsync extension
-
save(
String filename) → void -
Saves the model to
filename(.xml, .yml or .json). -
toString(
) → String -
A string representation of this object.
inherited
-
train(
Mat samples, int layout, Mat responses) → bool -
Trains the model on
samples(CV_32F, one sample per row for ROW_SAMPLE). -
trainAsync(
Mat samples, int layout, Mat responses) → Future< bool> -
Available on RTrees, provided by the RTreesAsync extension
-
trainWithData(
TrainData data, {int flags = 0}) → bool -
Trains the model on
data,flagsmay be StatModel.UPDATE_MODEL or model-specific flags. -
trainWithDataAsync(
TrainData data, {int flags = 0}) → Future< bool> -
Available on RTrees, provided by the RTreesAsync extension
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- finalizer → NativeFinalizer
-
final