Class cv::ml::StatModel#

Base class for statistical models in OpenCV ML.

#include <opencv2/ml.hpp>

Collaboration diagram for cv::ml::StatModel:

Public Types#

Public Member Functions#

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::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#

Base class for statistical models in OpenCV ML.

Member Enumeration Documentation#

enum Flags

UPDATE_MODEL
Python: cv.ml.StatModel_UPDATE_MODEL

RAW_OUTPUT
Python: cv.ml.StatModel_RAW_OUTPUT

makes the method return the raw results (the sum), not the class label

COMPRESSED_INPUT
Python: cv.ml.StatModel_COMPRESSED_INPUT

PREPROCESSED_INPUT
Python: cv.ml.StatModel_PREPROCESSED_INPUT

Member Function Documentation#

calcError()#

float cv::ml::StatModel::calcError(
const Ptr< TrainData > & data,
bool test,
OutputArray resp )

Python:

cv.ml.StatModel.calcError(data, test[, resp]) -> retval, resp

Computes error on the training or test dataset.

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%).

Parameters

  • data — the training data

  • test — 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.

  • resp — the optional output responses.

empty()#

bool cv::ml::StatModel::empty()

Python:

cv.ml.StatModel.empty() -> retval

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

getVarCount()#

int cv::ml::StatModel::getVarCount()

Python:

cv.ml.StatModel.getVarCount() -> retval

Returns the number of variables in training samples.

isClassifier()#

bool cv::ml::StatModel::isClassifier()

Python:

cv.ml.StatModel.isClassifier() -> retval

Returns true if the model is classifier.

isTrained()#

bool cv::ml::StatModel::isTrained()

Python:

cv.ml.StatModel.isTrained() -> retval

Returns true if the model is trained.

predict()#

float cv::ml::StatModel::predict(
InputArray samples,
OutputArray results = noArray(),
int flags = 0 )

Python:

cv.ml.StatModel.predict(samples[, results[, flags]]) -> retval, results

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

Parameters

  • samples — The input samples, floating-point matrix

  • results — The optional output matrix of results.

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

train()#

bool cv::ml::StatModel::train(
const Ptr< TrainData > & trainData,
int flags = 0 )

Python:

cv.ml.StatModel.train(trainData[, flags]) -> retval
cv.ml.StatModel.train(samples, layout, responses) -> retval

Trains the statistical model.

Parameters

train()#

bool cv::ml::StatModel::train(
InputArray samples,
int layout,
InputArray responses )

Python:

cv.ml.StatModel.train(trainData[, flags]) -> retval
cv.ml.StatModel.train(samples, layout, responses) -> retval

Trains the statistical model.

Parameters

  • samples — training samples

  • layout — See ml::SampleTypes.

  • responses — vector of responses associated with the training samples.

train()#

template<typename _Tp>
static Ptr< _Tp > cv::ml::StatModel::train(
const Ptr< TrainData > & data,
int flags = 0 )

Python:

cv.ml.StatModel.train(trainData[, flags]) -> retval
cv.ml.StatModel.train(samples, layout, responses) -> retval

Create and train model with default parameters.

The class must implement static create() method with no parameters or with all default parameter values

Source file#

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