Table of Contents

Class StatModel

Namespace
OpenCvSharp.ML
Assembly
OpenCvSharp.dll

Base class for statistical models in ML

public abstract class StatModel : Algorithm, IDisposable, ICvPtrHolder
Inheritance
StatModel
Implements
Derived
Inherited Members

Methods

CalcError(TrainData, bool, OutputArray)

Computes error on the training or test dataset

public virtual float CalcError(TrainData data, bool test, OutputArray resp)

Parameters

data 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.

resp OutputArray

the optional output responses.

Returns

float

Empty()

public virtual bool Empty()

Returns

bool

GetVarCount()

Returns the number of variables in training samples

public virtual int GetVarCount()

Returns

int

IsClassifier()

Returns true if the model is classifier

public virtual bool IsClassifier()

Returns

bool

IsTrained()

Returns true if the model is trained

public virtual bool IsTrained()

Returns

bool

Predict(InputArray, OutputArray?, Flags)

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

public virtual float Predict(InputArray samples, OutputArray? results = null, StatModel.Flags flags = (StatModel.Flags)0)

Parameters

samples InputArray

The input samples, floating-point matrix

results OutputArray

The optional output matrix of results.

flags StatModel.Flags

The optional flags, model-dependent.

Returns

float

Train(InputArray, SampleTypes, InputArray)

Trains the statistical model

public virtual bool Train(InputArray samples, SampleTypes layout, InputArray responses)

Parameters

samples InputArray

training samples

layout SampleTypes

SampleTypes value

responses InputArray

vector of responses associated with the training samples.

Returns

bool

Train(TrainData, int)

Trains the statistical model

public virtual bool Train(TrainData trainData, int flags = 0)

Parameters

trainData TrainData

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

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

Returns

bool