StatModel
Base class for statistical models in OpenCV ML.
Member of Ml
-
Declaration
Objective-C
- (BOOL)empty;
Swift
func empty() -> Bool
-
Returns true if the model is classifier
Declaration
Objective-C
- (BOOL)isClassifier;
Swift
func isClassifier() -> Bool
-
Returns true if the model is trained
Declaration
Objective-C
- (BOOL)isTrained;
Swift
func isTrained() -> Bool
-
Trains the statistical model
Declaration
Objective-C
- (BOOL)train:(nonnull TrainData *)trainData flags:(int)flags;
Swift
func train(trainData: TrainData, flags: Int32) -> Bool
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).
-
Trains the statistical model
Declaration
Objective-C
- (BOOL)train:(nonnull TrainData *)trainData;
Swift
func train(trainData: TrainData) -> Bool
Parameters
trainData
training data that can be loaded from file using TrainData::loadFromCSV or created with TrainData::create. new training samples, not completely overwritten (such as NormalBayesClassifier or ANN_MLP).
-
Computes error on the training or test dataset
Declaration
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.
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%).
-
Predicts response(s) for the provided sample(s)
Declaration
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.
-
Predicts response(s) for the provided sample(s)
Declaration
Parameters
samples
The input samples, floating-point matrix
results
The optional output matrix of results.
-
Returns the number of variables in training samples
Declaration
Objective-C
- (int)getVarCount;
Swift
func getVarCount() -> Int32