Class cv::ml::RTrees#

The class implements the random forest predictor. View details

#include <opencv2/ml.hpp>

Collaboration diagram for cv::ml::RTrees:

Public Types#

Public Types inherited from cv::ml::DTrees

Return

Name

Description

Flags

Public Types inherited from cv::ml::StatModel

Return

Name

Description

Flags

Public Member Functions#

Public Member Functions inherited from cv::ml::DTrees

Return

Name

Description

int

getCVFolds()

int

getMaxCategories()

int

getMaxDepth()

int

getMinSampleCount()

const std::vector< Node > &

getNodes()

Returns all the nodes.

cv::Mat

getPriors()

The array of a priori class probabilities, sorted by the class label value.

float

getRegressionAccuracy()

const std::vector< int > &

getRoots()

Returns indices of root nodes.

const std::vector< Split > &

getSplits()

Returns all the splits.

const std::vector< int > &

getSubsets()

Returns all the bitsets for categorical splits.

bool

getTruncatePrunedTree()

bool

getUse1SERule()

bool

getUseSurrogates()

void

setCVFolds(int val)

void

setMaxCategories(int val)

void

setMaxDepth(int val)

void

setMinSampleCount(int val)

void

setPriors(const cv::Mat & val)

The array of a priori class probabilities, sorted by the class label value.

void

setRegressionAccuracy(float val)

void

setTruncatePrunedTree(bool val)

void

setUse1SERule(bool val)

void

setUseSurrogates(bool val)

Public Member Functions inherited from cv::ml::StatModel

Return

Name

Description

float

calcError(
    const Ptr< TrainData > & data,
    bool test,
    OutputArray resp )

Computes error on the training or test dataset.

bool

empty()

Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read.

int

getVarCount()

Returns the number of variables in training samples.

bool

isClassifier()

Returns true if the model is classifier.

bool

isTrained()

Returns true if the model is trained.

float

predict(
    InputArray samples,
    OutputArray results = noArray(),
    int flags = 0 )

Predicts response(s) for the provided sample(s)

bool

train(
    const Ptr< TrainData > & trainData,
    int flags = 0 )

Trains the statistical model.

bool

train(
    InputArray samples,
    int layout,
    InputArray responses )

Trains the statistical model.

Public Member Functions inherited from cv::Algorithm

Return

Name

Description

Algorithm()

~Algorithm()

void

clear()

Clears the algorithm state.

bool

empty()

Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read.

String

getDefaultName()

void

read(const FileNode & fn)

Reads algorithm parameters from a file storage.

void

save(const String & filename)

void

write(
    const Ptr< FileStorage > & fs,
    const String & name = String() )

void

write(FileStorage & fs)

Stores algorithm parameters in a file storage.

void

write(
    FileStorage & fs,
    const String & name )

Static Public Member Functions#

Static Public Member Functions inherited from cv::ml::DTrees

Return

Name

Description

static Ptr< DTrees >

create()

Creates the empty model.

static Ptr< DTrees >

load(
    const String & filepath,
    const String & nodeName = String() )

Loads and creates a serialized DTrees from a file.

Static Public Member Functions inherited from cv::ml::StatModel

Return

Name

Description

static Ptr< _Tp >

train(
    const Ptr< TrainData > & data,
    int flags = 0 )

Create and train model with default parameters.

Static Public Member Functions inherited from cv::Algorithm

Return

Name

Description

static Ptr< _Tp >

load(
    const String & filename,
    const String & objname = String() )

Loads algorithm from the file.

static Ptr< _Tp >

loadFromString(
    const String & strModel,
    const String & objname = String() )

Loads algorithm from a String.

static Ptr< _Tp >

read(const FileNode & fn)

Reads algorithm from the file node.

Additional Inherited Members#

Protected Member Functions inherited from cv::Algorithm

Return

Name

Description

void

writeFormat(FileStorage & fs)

Detailed Description#

The class implements the random forest predictor.

See also

ml_intro_rtrees

Member Function Documentation#

getActiveVarCount()#

int cv::ml::RTrees::getActiveVarCount()

Python:

cv.ml.RTrees.getActiveVarCount() -> retval

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.

getCalculateVarImportance()#

bool cv::ml::RTrees::getCalculateVarImportance()

Python:

cv.ml.RTrees.getCalculateVarImportance() -> retval

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

getOOBError()#

double cv::ml::RTrees::getOOBError()

Returns the OOB error value, computed at the training stage when calcOOBError is set to true. If this flag was set to false, 0 is returned. The OOB error is also scaled by sample weighting.

getTermCriteria()#

TermCriteria cv::ml::RTrees::getTermCriteria()

Python:

cv.ml.RTrees.getTermCriteria() -> retval

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 also

setTermCriteria

getVarImportance()#

Mat cv::ml::RTrees::getVarImportance()

Python:

cv.ml.RTrees.getVarImportance() -> retval

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.

getVotes()#

void cv::ml::RTrees::getVotes(
InputArray samples,
OutputArray results,
int flags )

Python:

cv.ml.RTrees.getVotes(samples, flags[, results]) -> results

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.

Parameters

  • samples — Array containing the samples for which votes will be calculated.

  • results — Array where the result of the calculation will be written.

  • flags — Flags for defining the type of RTrees.

setActiveVarCount()#

void cv::ml::RTrees::setActiveVarCount(int val)

Python:

cv.ml.RTrees.setActiveVarCount(val)

setCalculateVarImportance()#

void cv::ml::RTrees::setCalculateVarImportance(bool val)

Python:

cv.ml.RTrees.setCalculateVarImportance(val)

setTermCriteria()#

void cv::ml::RTrees::setTermCriteria(const TermCriteria & val)

Python:

cv.ml.RTrees.setTermCriteria(val)

See also

getTermCriteria

create()#

static Ptr< RTrees > cv::ml::RTrees::create()

Python:

cv.ml.RTrees.create() -> retval
cv.ml.RTrees_create() -> retval

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.

load()#

static Ptr< RTrees > cv::ml::RTrees::load(
const String & filepath,
const String & nodeName = String() )

Python:

cv.ml.RTrees.load(filepath[, nodeName]) -> retval
cv.ml.RTrees_load(filepath[, nodeName]) -> retval

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

Parameters

  • filepath — path to serialized RTree

  • nodeName — name of node containing the classifier

Source file#

The documentation for this class was generated from the following file: