cv::ml::StatModel Class Reference abstract
机器学习

Base class for statistical models in OpenCV ML. 更多...

#include <opencv2/ml.hpp>

Inheritance diagram for cv::ml::StatModel:
cv::Algorithm cv::ml::ANN_MLP cv::ml::DTrees cv::ml::EM cv::ml::KNearest cv::ml::LogisticRegression cv::ml::NormalBayesClassifier cv::ml::SVM cv::ml::SVMSGD

公共类型

enum Flags {
UPDATE_MODEL = 1,
RAW_OUTPUT =1,
COMPRESSED_INPUT =2,
PREPROCESSED_INPUT =4
}

Public Member Functions

virtual float calcError (const Ptr < TrainData > &data, bool test, OutputArray resp) const
Computes error on the training or test dataset. 更多...
virtual bool empty () const CV_OVERRIDE
返回 true 若 Algorithm is empty (e.g. in the very beginning or after unsuccessful read. 更多...
virtual int getVarCount () const =0
Returns the number of variables in training samples. 更多...
virtual bool isClassifier () const =0
Returns true if the model is classifier. 更多...
virtual bool isTrained () const =0
Returns true if the model is trained. 更多...
virtual float predict ( InputArray samples, OutputArray results= noArray (), int flags=0) const =0
Predicts response(s) for the provided sample(s) 更多...
virtual bool train (const Ptr < TrainData > &trainData, int flags=0)
Trains the statistical model. 更多...
virtual bool train ( InputArray samples, int layout, InputArray responses)
Trains the statistical model. 更多...
- Public Member Functions inherited from cv::Algorithm
Algorithm ()
virtual ~Algorithm ()
virtual void clear ()
Clears the algorithm state. 更多...
virtual 字符串 getDefaultName () const
virtual void read (const FileNode &fn)
Reads algorithm parameters from a file storage. 更多...
virtual void save (const 字符串 &filename) const
virtual void write ( FileStorage &fs) const
Stores algorithm parameters in a file storage. 更多...
void write (const Ptr < FileStorage > &fs, const 字符串 &name= 字符串 ()) 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. 更多...

Static Public Member Functions

template<typename _Tp >
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
template<typename _Tp >
static Ptr < _Tp > load (const 字符串 &filename, const 字符串 &objname= 字符串 ())
Loads algorithm from the file. 更多...
template<typename _Tp >
static Ptr < _Tp > loadFromString (const 字符串 &strModel, const 字符串 &objname= 字符串 ())
Loads algorithm from a String. 更多...
template<typename _Tp >
static Ptr < _Tp > read (const FileNode &fn)
Reads algorithm from the file node. 更多...

额外继承成员

- Protected Member Functions inherited from cv::Algorithm
void writeFormat ( FileStorage &fs) const

详细描述

Base class for statistical models in OpenCV ML.

Member Enumeration Documentation

Flags

Predict options

枚举器
UPDATE_MODEL
RAW_OUTPUT

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

COMPRESSED_INPUT
PREPROCESSED_INPUT

成员函数文档编制

calcError()

virtual float cv::ml::StatModel::calcError ( const Ptr < TrainData > & data ,
bool test ,
OutputArray resp
) const
virtual
Python:
retval, resp = cv.ml_StatModel.calcError( data, test[, resp] )

Computes error on the training or test dataset.

参数
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.

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

empty()

virtual bool cv::ml::StatModel::empty ( ) const
virtual
Python:
retval = cv.ml_StatModel.empty( )

返回 true 若 Algorithm is empty (e.g. in the very beginning or after unsuccessful read.

Reimplemented from cv::Algorithm .

getVarCount()

virtual int cv::ml::StatModel::getVarCount ( ) const
pure virtual
Python:
retval = cv.ml_StatModel.getVarCount( )

Returns the number of variables in training samples.

isClassifier()

virtual bool cv::ml::StatModel::isClassifier ( ) const
pure virtual
Python:
retval = cv.ml_StatModel.isClassifier( )

Returns true if the model is classifier.

isTrained()

virtual bool cv::ml::StatModel::isTrained ( ) const
pure virtual
Python:
retval = cv.ml_StatModel.isTrained( )

Returns true if the model is trained.

predict()

virtual float cv::ml::StatModel::predict ( InputArray samples ,
OutputArray 结果 = noArray () ,
int flags = 0
) const
pure virtual
Python:
retval, results = cv.ml_StatModel.predict( samples[, results[, flags]] )

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

参数
samples The input samples, floating-point matrix
结果 The optional output matrix of results.
flags The optional flags, model-dependent. See cv::ml::StatModel::Flags .

Implemented in cv::ml::LogisticRegression ,和 cv::ml::EM .

train() [1/3]

virtual bool cv::ml::StatModel::train ( const Ptr < TrainData > & trainData ,
int flags = 0
)
virtual
Python:
retval = cv.ml_StatModel.train( trainData[, flags] )
retval = cv.ml_StatModel.train( samples, layout, responses )

Trains the statistical model.

参数
trainData training data that can be loaded from file using TrainData::loadFromCSV or created with TrainData::create .
flags 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 ).

train() [2/3]

virtual bool cv::ml::StatModel::train ( InputArray samples ,
int layout ,
InputArray responses
)
virtual
Python:
retval = cv.ml_StatModel.train( trainData[, flags] )
retval = cv.ml_StatModel.train( samples, layout, responses )

Trains the statistical model.

参数
samples training samples
layout ml::SampleTypes .
responses vector of responses associated with the training samples.

train() [3/3]

template<typename _Tp >
static Ptr <_Tp> cv::ml::StatModel::train ( const Ptr < TrainData > & data ,
int flags = 0
)
inline static
Python:
retval = cv.ml_StatModel.train( trainData[, flags] )
retval = cv.ml_StatModel.train( samples, layout, responses )

Create and train model with default parameters.

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


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