OpenCV  4.0.0
Open Source Computer Vision
Public Member Functions | Static Public Member Functions | List of all members
cv::ml::RTrees Class Referenceabstract

The class implements the random forest predictor. More...

#include "ml.hpp"

Inheritance diagram for cv::ml::RTrees:
cv::ml::DTrees cv::ml::StatModel cv::Algorithm

Public Member Functions

virtual int getActiveVarCount () const =0
 
virtual bool getCalculateVarImportance () const =0
 
virtual TermCriteria getTermCriteria () const =0
 
virtual Mat getVarImportance () const =0
 
virtual void getVotes (InputArray samples, OutputArray results, int flags) const =0
 
virtual void setActiveVarCount (int val)=0
 
virtual void setCalculateVarImportance (bool val)=0
 
virtual void setTermCriteria (const TermCriteria &val)=0
 
- Public Member Functions inherited from cv::ml::DTrees
virtual int getCVFolds () const =0
 
virtual int getMaxCategories () const =0
 
virtual int getMaxDepth () const =0
 
virtual int getMinSampleCount () const =0
 
virtual const std::vector< Node > & getNodes () const =0
 Returns all the nodes. More...
 
virtual cv::Mat getPriors () const =0
 The array of a priori class probabilities, sorted by the class label value. More...
 
virtual float getRegressionAccuracy () const =0
 
virtual const std::vector< int > & getRoots () const =0
 Returns indices of root nodes. More...
 
virtual const std::vector< Split > & getSplits () const =0
 Returns all the splits. More...
 
virtual const std::vector< int > & getSubsets () const =0
 Returns all the bitsets for categorical splits. More...
 
virtual bool getTruncatePrunedTree () const =0
 
virtual bool getUse1SERule () const =0
 
virtual bool getUseSurrogates () const =0
 
virtual void setCVFolds (int val)=0
 
virtual void setMaxCategories (int val)=0
 
virtual void setMaxDepth (int val)=0
 
virtual void setMinSampleCount (int val)=0
 
virtual void setPriors (const cv::Mat &val)=0
 The array of a priori class probabilities, sorted by the class label value. More...
 
virtual void setRegressionAccuracy (float val)=0
 
virtual void setTruncatePrunedTree (bool val)=0
 
virtual void setUse1SERule (bool val)=0
 
virtual void setUseSurrogates (bool val)=0
 
- Public Member Functions inherited from cv::ml::StatModel
virtual float calcError (const Ptr< TrainData > &data, bool test, OutputArray resp) const
 Computes error on the training or test dataset. More...
 
virtual bool empty () const CV_OVERRIDE
 Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read. More...
 
virtual int getVarCount () const =0
 Returns the number of variables in training samples. More...
 
virtual bool isClassifier () const =0
 Returns true if the model is classifier. More...
 
virtual bool isTrained () const =0
 Returns true if the model is trained. More...
 
virtual float predict (InputArray samples, OutputArray results=noArray(), int flags=0) const =0
 Predicts response(s) for the provided sample(s) More...
 
virtual bool train (const Ptr< TrainData > &trainData, int flags=0)
 Trains the statistical model. More...
 
virtual bool train (InputArray samples, int layout, InputArray responses)
 Trains the statistical model. More...
 
- Public Member Functions inherited from cv::Algorithm
 Algorithm ()
 
virtual ~Algorithm ()
 
virtual void clear ()
 Clears the algorithm state. More...
 
virtual String getDefaultName () const
 
virtual void read (const FileNode &fn)
 Reads algorithm parameters from a file storage. More...
 
virtual void save (const String &filename) const
 
virtual void write (FileStorage &fs) const
 Stores algorithm parameters in a file storage. More...
 
void write (const Ptr< FileStorage > &fs, const String &name=String()) const
 simplified API for language bindings This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 

Static Public Member Functions

static Ptr< RTreescreate ()
 
static Ptr< RTreesload (const String &filepath, const String &nodeName=String())
 Loads and creates a serialized RTree from a file. More...
 
- Static Public Member Functions inherited from cv::ml::DTrees
static Ptr< DTreescreate ()
 Creates the empty model. More...
 
static Ptr< DTreesload (const String &filepath, const String &nodeName=String())
 Loads and creates a serialized DTrees from a file. More...
 
- Static Public Member Functions inherited from cv::ml::StatModel
template<typename _Tp >
static Ptr< _Tp > train (const Ptr< TrainData > &data, int flags=0)
 Create and train model with default parameters. More...
 
- Static Public Member Functions inherited from cv::Algorithm
template<typename _Tp >
static Ptr< _Tp > load (const String &filename, const String &objname=String())
 Loads algorithm from the file. More...
 
template<typename _Tp >
static Ptr< _Tp > loadFromString (const String &strModel, const String &objname=String())
 Loads algorithm from a String. More...
 
template<typename _Tp >
static Ptr< _Tp > read (const FileNode &fn)
 Reads algorithm from the file node. More...
 

Additional Inherited Members

- Public Types inherited from cv::ml::DTrees
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
enum  Flags {
  UPDATE_MODEL = 1,
  RAW_OUTPUT =1,
  COMPRESSED_INPUT =2,
  PREPROCESSED_INPUT =4
}
 
- Protected Member Functions inherited from cv::Algorithm
void writeFormat (FileStorage &fs) const
 

Detailed Description

The class implements the random forest predictor.

See also
Random Trees

Member Function Documentation

§ create()

static Ptr<RTrees> cv::ml::RTrees::create ( )
static
Python:
retval=cv.ml.RTrees_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.

§ getActiveVarCount()

virtual int cv::ml::RTrees::getActiveVarCount ( ) const
pure virtual
Python:
retval=cv.ml_RTrees.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 also
setActiveVarCount

§ getCalculateVarImportance()

virtual bool cv::ml::RTrees::getCalculateVarImportance ( ) const
pure virtual
Python:
retval=cv.ml_RTrees.getCalculateVarImportance()

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

See also
setCalculateVarImportance

§ getTermCriteria()

virtual TermCriteria cv::ml::RTrees::getTermCriteria ( ) const
pure virtual
Python:
retval=cv.ml_RTrees.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 also
setTermCriteria

§ getVarImportance()

virtual Mat cv::ml::RTrees::getVarImportance ( ) const
pure virtual
Python:
retval=cv.ml_RTrees.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.

§ getVotes()

virtual void cv::ml::RTrees::getVotes ( InputArray  samples,
OutputArray  results,
int  flags 
) const
pure virtual
Python:
results=cv.ml_RTrees.getVotes(samples, flags[, 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
samplesArray containing the samples for which votes will be calculated.
resultsArray where the result of the calculation will be written.
flagsFlags for defining the type of RTrees.

§ load()

static Ptr<RTrees> cv::ml::RTrees::load ( const String filepath,
const String nodeName = String() 
)
static
Python:
retval=cv.ml.RTrees_load(filepath[, nodeName])

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
filepathpath to serialized RTree
nodeNamename of node containing the classifier

§ setActiveVarCount()

virtual void cv::ml::RTrees::setActiveVarCount ( int  val)
pure virtual
Python:
None=cv.ml_RTrees.setActiveVarCount(val)

§ setCalculateVarImportance()

virtual void cv::ml::RTrees::setCalculateVarImportance ( bool  val)
pure virtual
Python:
None=cv.ml_RTrees.setCalculateVarImportance(val)

§ setTermCriteria()

virtual void cv::ml::RTrees::setTermCriteria ( const TermCriteria val)
pure virtual
Python:
None=cv.ml_RTrees.setTermCriteria(val)

See also
getTermCriteria

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