Class cv::ml::StatModel#
Base class for statistical models in OpenCV ML.
#include <opencv2/ml.hpp>Collaboration diagram for cv::ml::StatModel:
Public Types#
enum Flags {
UPDATE_MODEL = 1,
RAW_OUTPUT =1,
COMPRESSED_INPUT =2,
PREPROCESSED_INPUT =4
}Public Member Functions#
Public Member Functions inherited from cv::Algorithm
Return |
Name |
Description |
|---|---|---|
|
Clears the algorithm state. |
|
|
Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read. |
|
|
Reads algorithm parameters from a file storage. |
|
|
||
|
|
|
|
Stores algorithm parameters in a file storage. |
|
|
Static Public Member Functions#
Static Public Member Functions inherited from cv::Algorithm
Return |
Name |
Description |
|---|---|---|
|
|
Loads algorithm from the file. |
|
|
Loads algorithm from a String. |
|
Reads algorithm from the file node. |
Additional Inherited Members#
Protected Member Functions inherited from cv::Algorithm
Return |
Name |
Description |
|---|---|---|
|
Detailed Description#
Base class for statistical models in OpenCV ML.
Member Enumeration Documentation#
enum Flags
|
|
|
makes the method return the raw results (the sum), not the class label |
|
|
|
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 datatest— 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 matrixresults— 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
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()#
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 sampleslayout— 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:
opencv2/ml.hpp