Skip to content

ml_RTrees

mlclassOpenCV 5.0.0
import { ml_RTrees } 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_DTrees.


Random Trees Classifier * *************************************************************************************** The class implements the random forest predictor.

See: ml_intro_rtrees

Constructors and members

static create

Creates the empty model. Use StatModel::train to train the model, StatModel::train to create and train the model, Algorithm::load to load the pre-trained model.

create(): ml_RTrees | null;
Returns

The ml_RTrees | null result.

static load

Loads and creates a serialized RTree from a file

Use RTree::save to serialize and store an RTree to disk. Load the RTree 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_RTrees | null;
2 available overloads
load(filepath: EmbindString): ml_RTrees | null;
load(filepath: EmbindString, nodeName: EmbindString): ml_RTrees | null;
filepath

path to serialized RTree

nodeName

name of node containing the classifier

Returns

The ml_RTrees | 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;
Returns

The this result.

getCalculateVarImportance

If true then variable importance will be calculated and then it can be retrieved by RTrees::getVarImportance. Default value is false. See: setCalculateVarImportance

getCalculateVarImportance(): boolean;
Returns

The boolean result.

setCalculateVarImportance

If true then variable importance will be calculated and then it can be retrieved by RTrees::getVarImportance. Default value is false. See: setCalculateVarImportance See: getCalculateVarImportance

setCalculateVarImportance(val: boolean): void;
val

val argument (boolean).

getActiveVarCount

The size of the randomly selected subset of features at each tree node and that are used to find the best split(s). If you set it to 0 then the size will be set to the square root of the total number of features. Default value is 0. See: setActiveVarCount

getActiveVarCount(): number;
Returns

The number result.

setActiveVarCount

The size of the randomly selected subset of features at each tree node and that are used to find the best split(s). If you set it to 0 then the size will be set to the square root of the total number of features. Default value is 0. See: setActiveVarCount See: getActiveVarCount

setActiveVarCount(val: number): void;
val

val argument (number).

getTermCriteria

The termination criteria that specifies when the training algorithm stops. Either when the specified number of trees is trained and added to the ensemble or when sufficient accuracy (measured as OOB error) is achieved. Typically the more trees you have the better the accuracy. However, the improvement in accuracy generally diminishes and asymptotes pass a certain number of trees. Also to keep in mind, the number of tree increases the prediction time linearly. Default value is TermCriteria(TermCriteria::MAX_ITERS + TermCriteria::EPS, 50, 0.1) See: setTermCriteria

getTermCriteria(): TermCriteria;
Returns

The TermCriteria result.

setTermCriteria

The termination criteria that specifies when the training algorithm stops. Either when the specified number of trees is trained and added to the ensemble or when sufficient accuracy (measured as OOB error) is achieved. Typically the more trees you have the better the accuracy. However, the improvement in accuracy generally diminishes and asymptotes pass a certain number of trees. Also to keep in mind, the number of tree increases the prediction time linearly. Default value is TermCriteria(TermCriteria::MAX_ITERS + TermCriteria::EPS, 50, 0.1) See: setTermCriteria See: getTermCriteria

setTermCriteria(val: TermCriteria): void;
val

val argument (TermCriteria).

getVarImportance

Returns the variable importance array. The method returns the variable importance vector, computed at the training stage when CalculateVarImportance is set to true. If this flag was set to false, the empty matrix is returned.

getVarImportance(): Mat;
Returns

The Mat result. Release returned native handles with using or delete(), including handles nested in results.

getVotes

Returns the result of each individual tree in the forest. In case the model is a regression problem, the method will return each of the trees' results for each of the sample cases. If the model is a classifier, it will return a Mat with samples + 1 rows, where the first row gives the class number and the following rows return the votes each class had for each sample.

getVotes(samples: Mat, results: Mat, flags: number): void;
samples

Array containing the samples for which votes will be calculated.

results

Output destination, filled by the native operation. Array where the result of the calculation will be written.

flags

Flags for defining the type of RTrees.

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.