View Source Evision.ML.RTrees (Evision v0.1.15)

Link to this section Summary

Types

t()

Type that represents an Evision.ML.RTrees struct.

Functions

Computes error on the training or test dataset

Computes error on the training or test dataset

Clears the algorithm state

Return

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.

Return
  • retval: bool

Python prototype (for reference):

Return
  • retval: int

@see setCVFolds/2

Return

Returns the algorithm string identifier. This string is used as top level xml/yml node tag when the object is saved to a file or string.

Return
  • retval: int

@see setMaxDepth/2

Return
  • retval: double

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.

Return
  • retval: cv::Mat

@see setPriors/2

Return
  • retval: TermCriteria

@see setTermCriteria/2

Return
  • retval: bool

@see setUse1SERule/2

Returns the number of variables in training samples

Return

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.

Positional Arguments
Positional Arguments

Returns true if the model is classifier

Returns true if the model is trained

Loads and creates a serialized RTree from a file

Loads and creates a serialized RTree from a file

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

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

Reads algorithm parameters from a file storage

Positional Arguments

Saves the algorithm to a file. In order to make this method work, the derived class must implement Algorithm::write(FileStorage& fs).

Positional Arguments
  • val: int

@see getActiveVarCount/1

Positional Arguments
  • val: int

@see getCVFolds/1

Positional Arguments
  • val: int

@see getMaxCategories/1

Positional Arguments
  • val: int

@see getMaxDepth/1

Positional Arguments
  • val: int

@see getMinSampleCount/1

Positional Arguments

@see getPriors/1

Positional Arguments
  • val: float

@see getRegressionAccuracy/1

Positional Arguments
  • val: TermCriteria

@see getTermCriteria/1

Positional Arguments
  • val: bool

@see getTruncatePrunedTree/1

Positional Arguments
  • val: bool

@see getUse1SERule/1

Positional Arguments
  • val: bool

@see getUseSurrogates/1

Trains the statistical model

Trains the statistical model

Trains the statistical model

simplified API for language bindings

simplified API for language bindings

Link to this section Types

@type t() :: %Evision.ML.RTrees{ref: reference()}

Type that represents an Evision.ML.RTrees struct.

  • ref. reference()

    The underlying erlang resource variable.

Link to this section Functions

Link to this function

calcError(self, data, test)

View Source
@spec calcError(t(), Evision.ML.TrainData.t(), boolean()) ::
  {number(), Evision.Mat.t()} | {:error, String.t()}

Computes error on the training or test dataset

Positional Arguments
  • data: Evision.ML.TrainData.

    the training data

  • test: bool.

    if true, the error is computed over the test subset of the data, otherwise it's computed over the training subset of the data. Please note that if you loaded a completely different dataset to evaluate already trained classifier, you will probably want not to set the test subset at all with TrainData::setTrainTestSplitRatio and specify test=false, so that the error is computed for the whole new set. Yes, this sounds a bit confusing.

Return
  • retval: float

  • resp: Evision.Mat.

    the optional output responses.

The method uses StatModel::predict to compute the error. For regression models the error is computed as RMS, for classifiers - as a percent of missclassified samples (0%-100%).

Python prototype (for reference):

calcError(data, test[, resp]) -> retval, resp
Link to this function

calcError(self, data, test, opts)

View Source
@spec calcError(
  t(),
  Evision.ML.TrainData.t(),
  boolean(),
  [{atom(), term()}, ...] | nil
) ::
  {number(), Evision.Mat.t()} | {:error, String.t()}

Computes error on the training or test dataset

Positional Arguments
  • data: Evision.ML.TrainData.

    the training data

  • test: bool.

    if true, the error is computed over the test subset of the data, otherwise it's computed over the training subset of the data. Please note that if you loaded a completely different dataset to evaluate already trained classifier, you will probably want not to set the test subset at all with TrainData::setTrainTestSplitRatio and specify test=false, so that the error is computed for the whole new set. Yes, this sounds a bit confusing.

Return
  • retval: float

  • resp: Evision.Mat.

    the optional output responses.

The method uses StatModel::predict to compute the error. For regression models the error is computed as RMS, for classifiers - as a percent of missclassified samples (0%-100%).

Python prototype (for reference):

calcError(data, test[, resp]) -> retval, resp
@spec clear(t()) :: :ok | {:error, String.t()}

Clears the algorithm state

Python prototype (for reference):

clear() -> None
@spec create() :: t() | {:error, String.t()}
Return

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.

Python prototype (for reference):

create() -> retval
@spec empty(t()) :: boolean() | {:error, String.t()}
Return
  • retval: bool

Python prototype (for reference):

empty() -> retval
@spec getActiveVarCount(t()) :: integer() | {:error, String.t()}
Return
  • retval: int

@see setActiveVarCount/2

Python prototype (for reference):

getActiveVarCount() -> retval
Link to this function

getCalculateVarImportance(self)

View Source
@spec getCalculateVarImportance(t()) :: boolean() | {:error, String.t()}
Return
  • retval: bool

@see setCalculateVarImportance/2

Python prototype (for reference):

getCalculateVarImportance() -> retval
@spec getCVFolds(t()) :: integer() | {:error, String.t()}
Return
  • retval: int

@see setCVFolds/2

Python prototype (for reference):

getCVFolds() -> retval
@spec getDefaultName(t()) :: binary() | {:error, String.t()}
Return

Returns the algorithm string identifier. This string is used as top level xml/yml node tag when the object is saved to a file or string.

Python prototype (for reference):

getDefaultName() -> retval
@spec getMaxCategories(t()) :: integer() | {:error, String.t()}
Return
  • retval: int

@see setMaxCategories/2

Python prototype (for reference):

getMaxCategories() -> retval
@spec getMaxDepth(t()) :: integer() | {:error, String.t()}
Return
  • retval: int

@see setMaxDepth/2

Python prototype (for reference):

getMaxDepth() -> retval
@spec getMinSampleCount(t()) :: integer() | {:error, String.t()}
Return
  • retval: int

@see setMinSampleCount/2

Python prototype (for reference):

getMinSampleCount() -> retval
@spec getOOBError(t()) :: number() | {:error, String.t()}
Return
  • retval: double

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.

Python prototype (for reference):

getOOBError() -> retval
@spec getPriors(t()) :: Evision.Mat.t() | {:error, String.t()}
Return
  • retval: cv::Mat

@see setPriors/2

Python prototype (for reference):

getPriors() -> retval
Link to this function

getRegressionAccuracy(self)

View Source
@spec getRegressionAccuracy(t()) :: number() | {:error, String.t()}
Return
  • retval: float

@see setRegressionAccuracy/2

Python prototype (for reference):

getRegressionAccuracy() -> retval
@spec getTermCriteria(t()) :: {integer(), integer(), number()} | {:error, String.t()}
Return
  • retval: TermCriteria

@see setTermCriteria/2

Python prototype (for reference):

getTermCriteria() -> retval
Link to this function

getTruncatePrunedTree(self)

View Source
@spec getTruncatePrunedTree(t()) :: boolean() | {:error, String.t()}
Return
  • retval: bool

@see setTruncatePrunedTree/2

Python prototype (for reference):

getTruncatePrunedTree() -> retval
@spec getUse1SERule(t()) :: boolean() | {:error, String.t()}
Return
  • retval: bool

@see setUse1SERule/2

Python prototype (for reference):

getUse1SERule() -> retval
@spec getUseSurrogates(t()) :: boolean() | {:error, String.t()}
Return
  • retval: bool

@see setUseSurrogates/2

Python prototype (for reference):

getUseSurrogates() -> retval
@spec getVarCount(t()) :: integer() | {:error, String.t()}

Returns the number of variables in training samples

Return
  • retval: int

Python prototype (for reference):

getVarCount() -> retval
@spec getVarImportance(t()) :: Evision.Mat.t() | {:error, String.t()}
Return

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.

Python prototype (for reference):

getVarImportance() -> retval
Link to this function

getVotes(self, samples, flags)

View Source
@spec getVotes(t(), Evision.Mat.maybe_mat_in(), integer()) ::
  Evision.Mat.t() | {:error, String.t()}
Positional Arguments
  • samples: Evision.Mat.

    Array containing the samples for which votes will be calculated.

  • flags: int.

    Flags for defining the type of RTrees.

Return
  • results: Evision.Mat.

    Array where the result of the calculation will be written.

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.

Python prototype (for reference):

getVotes(samples, flags[, results]) -> results
Link to this function

getVotes(self, samples, flags, opts)

View Source
@spec getVotes(
  t(),
  Evision.Mat.maybe_mat_in(),
  integer(),
  [{atom(), term()}, ...] | nil
) ::
  Evision.Mat.t() | {:error, String.t()}
Positional Arguments
  • samples: Evision.Mat.

    Array containing the samples for which votes will be calculated.

  • flags: int.

    Flags for defining the type of RTrees.

Return
  • results: Evision.Mat.

    Array where the result of the calculation will be written.

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.

Python prototype (for reference):

getVotes(samples, flags[, results]) -> results
@spec isClassifier(t()) :: boolean() | {:error, String.t()}

Returns true if the model is classifier

Return
  • retval: bool

Python prototype (for reference):

isClassifier() -> retval
@spec isTrained(t()) :: boolean() | {:error, String.t()}

Returns true if the model is trained

Return
  • retval: bool

Python prototype (for reference):

isTrained() -> retval
@spec load(binary()) :: t() | {:error, String.t()}

Loads and creates a serialized RTree from a file

Positional Arguments
  • filepath: String.

    path to serialized RTree

Keyword Arguments
  • nodeName: String.

    name of node containing the classifier

Return

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

Python prototype (for reference):

load(filepath[, nodeName]) -> retval
@spec load(binary(), [{atom(), term()}, ...] | nil) :: t() | {:error, String.t()}

Loads and creates a serialized RTree from a file

Positional Arguments
  • filepath: String.

    path to serialized RTree

Keyword Arguments
  • nodeName: String.

    name of node containing the classifier

Return

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

Python prototype (for reference):

load(filepath[, nodeName]) -> retval
@spec predict(t(), Evision.Mat.maybe_mat_in()) ::
  {number(), Evision.Mat.t()} | {:error, String.t()}

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

Positional Arguments
  • samples: Evision.Mat.

    The input samples, floating-point matrix

Keyword Arguments
  • flags: int.

    The optional flags, model-dependent. See cv::ml::StatModel::Flags.

Return
  • retval: float

  • results: Evision.Mat.

    The optional output matrix of results.

Python prototype (for reference):

predict(samples[, results[, flags]]) -> retval, results
Link to this function

predict(self, samples, opts)

View Source
@spec predict(t(), Evision.Mat.maybe_mat_in(), [{atom(), term()}, ...] | nil) ::
  {number(), Evision.Mat.t()} | {:error, String.t()}

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

Positional Arguments
  • samples: Evision.Mat.

    The input samples, floating-point matrix

Keyword Arguments
  • flags: int.

    The optional flags, model-dependent. See cv::ml::StatModel::Flags.

Return
  • retval: float

  • results: Evision.Mat.

    The optional output matrix of results.

Python prototype (for reference):

predict(samples[, results[, flags]]) -> retval, results
@spec read(t(), Evision.FileNode.t()) :: :ok | {:error, String.t()}

Reads algorithm parameters from a file storage

Positional Arguments

Python prototype (for reference):

read(fn_) -> None
@spec save(t(), binary()) :: :ok | {:error, String.t()}
Positional Arguments

Saves the algorithm to a file. In order to make this method work, the derived class must implement Algorithm::write(FileStorage& fs).

Python prototype (for reference):

save(filename) -> None
Link to this function

setActiveVarCount(self, val)

View Source
@spec setActiveVarCount(t(), integer()) :: :ok | {:error, String.t()}
Positional Arguments
  • val: int

@see getActiveVarCount/1

Python prototype (for reference):

setActiveVarCount(val) -> None
Link to this function

setCalculateVarImportance(self, val)

View Source
@spec setCalculateVarImportance(t(), boolean()) :: :ok | {:error, String.t()}
Positional Arguments
  • val: bool

@see getCalculateVarImportance/1

Python prototype (for reference):

setCalculateVarImportance(val) -> None
@spec setCVFolds(t(), integer()) :: :ok | {:error, String.t()}
Positional Arguments
  • val: int

@see getCVFolds/1

Python prototype (for reference):

setCVFolds(val) -> None
Link to this function

setMaxCategories(self, val)

View Source
@spec setMaxCategories(t(), integer()) :: :ok | {:error, String.t()}
Positional Arguments
  • val: int

@see getMaxCategories/1

Python prototype (for reference):

setMaxCategories(val) -> None
@spec setMaxDepth(t(), integer()) :: :ok | {:error, String.t()}
Positional Arguments
  • val: int

@see getMaxDepth/1

Python prototype (for reference):

setMaxDepth(val) -> None
Link to this function

setMinSampleCount(self, val)

View Source
@spec setMinSampleCount(t(), integer()) :: :ok | {:error, String.t()}
Positional Arguments
  • val: int

@see getMinSampleCount/1

Python prototype (for reference):

setMinSampleCount(val) -> None
@spec setPriors(t(), Evision.Mat.maybe_mat_in()) :: :ok | {:error, String.t()}
Positional Arguments

@see getPriors/1

Python prototype (for reference):

setPriors(val) -> None
Link to this function

setRegressionAccuracy(self, val)

View Source
@spec setRegressionAccuracy(t(), number()) :: :ok | {:error, String.t()}
Positional Arguments
  • val: float

@see getRegressionAccuracy/1

Python prototype (for reference):

setRegressionAccuracy(val) -> None
Link to this function

setTermCriteria(self, val)

View Source
@spec setTermCriteria(t(), {integer(), integer(), number()}) ::
  :ok | {:error, String.t()}
Positional Arguments
  • val: TermCriteria

@see getTermCriteria/1

Python prototype (for reference):

setTermCriteria(val) -> None
Link to this function

setTruncatePrunedTree(self, val)

View Source
@spec setTruncatePrunedTree(t(), boolean()) :: :ok | {:error, String.t()}
Positional Arguments
  • val: bool

@see getTruncatePrunedTree/1

Python prototype (for reference):

setTruncatePrunedTree(val) -> None
Link to this function

setUse1SERule(self, val)

View Source
@spec setUse1SERule(t(), boolean()) :: :ok | {:error, String.t()}
Positional Arguments
  • val: bool

@see getUse1SERule/1

Python prototype (for reference):

setUse1SERule(val) -> None
Link to this function

setUseSurrogates(self, val)

View Source
@spec setUseSurrogates(t(), boolean()) :: :ok | {:error, String.t()}
Positional Arguments
  • val: bool

@see getUseSurrogates/1

Python prototype (for reference):

setUseSurrogates(val) -> None
@spec train(t(), Evision.ML.TrainData.t()) :: boolean() | {:error, String.t()}

Trains the statistical model

Positional Arguments
  • trainData: Evision.ML.TrainData.

    training data that can be loaded from file using TrainData::loadFromCSV or created with TrainData::create.

Keyword Arguments
  • flags: int.

    optional flags, depending on the model. Some of the models can be updated with the new training samples, not completely overwritten (such as NormalBayesClassifier or ANN_MLP).

Return
  • retval: bool

Python prototype (for reference):

train(trainData[, flags]) -> retval
Link to this function

train(self, trainData, opts)

View Source
@spec train(t(), Evision.ML.TrainData.t(), [{atom(), term()}, ...] | nil) ::
  boolean() | {:error, String.t()}

Trains the statistical model

Positional Arguments
  • trainData: Evision.ML.TrainData.

    training data that can be loaded from file using TrainData::loadFromCSV or created with TrainData::create.

Keyword Arguments
  • flags: int.

    optional flags, depending on the model. Some of the models can be updated with the new training samples, not completely overwritten (such as NormalBayesClassifier or ANN_MLP).

Return
  • retval: bool

Python prototype (for reference):

train(trainData[, flags]) -> retval
Link to this function

train(self, samples, layout, responses)

View Source
@spec train(t(), Evision.Mat.maybe_mat_in(), integer(), Evision.Mat.maybe_mat_in()) ::
  boolean() | {:error, String.t()}

Trains the statistical model

Positional Arguments
  • samples: Evision.Mat.

    training samples

  • layout: int.

    See ml::SampleTypes.

  • responses: Evision.Mat.

    vector of responses associated with the training samples.

Return
  • retval: bool

Python prototype (for reference):

train(samples, layout, responses) -> retval
@spec write(t(), Evision.FileStorage.t()) :: :ok | {:error, String.t()}

simplified API for language bindings

Positional Arguments
Keyword Arguments

Has overloading in C++

Python prototype (for reference):

write(fs[, name]) -> None
@spec write(t(), Evision.FileStorage.t(), [{atom(), term()}, ...] | nil) ::
  :ok | {:error, String.t()}

simplified API for language bindings

Positional Arguments
Keyword Arguments

Has overloading in C++

Python prototype (for reference):

write(fs[, name]) -> None