ml_StatModel
import { ml_StatModel } from '@banou/opencv-wasm'Use after await initOpenCV(). See the initialization and named imports guide.
Native object: release it with using or delete(). Factories can return null; check before calling methods. Inherits Algorithm.
Base class for statistical models in OpenCV ML.
Constructors and members
clone
Create another handle to the same native object. This retains the object without copying its pixels or algorithm state; dispose both handles separately.
clone(): this;The this result.
getVarCount
Returns the number of variables in training samples
getVarCount(): number;The number result.
empty
Return whether the statistical model has no learned parameters.
empty(): boolean;The boolean result.
isTrained
Returns true if the model is trained
isTrained(): boolean;The boolean result.
isClassifier
Returns true if the model is classifier
isClassifier(): boolean;The boolean result.
train
Trains the statistical model
train(trainData: ml_TrainData | null, flags: number): boolean;2 available overloads
train(trainData: ml_TrainData | null): boolean;train(trainData: ml_TrainData | null, flags: number): boolean;trainDatatraining data that can be loaded from file using TrainData::loadFromCSV or created with TrainData::create.
flagsoptional 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).
The boolean result.
train1
Trains the statistical model
train1(samples: Mat, layout: number, responses: Mat): boolean;samplestraining samples
layoutSee ml::SampleTypes.
responsesvector of responses associated with the training samples.
The boolean result.
calcError
Computes error on the training or test dataset
calcError(data: ml_TrainData | null, test: boolean, resp: Mat): number;datathe training data
testif 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.
respOutput destination, filled by the native operation. 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%).
The number result.
predict
Predicts response(s) for the provided sample(s)
predict(samples: Mat, results: Mat, flags: number): number;3 available overloads
predict(samples: Mat): number;predict(samples: Mat, results: Mat): number;predict(samples: Mat, results: Mat, flags: number): number;samplesThe input samples, floating-point matrix
resultsOutput destination, filled by the native operation. The optional output matrix of results.
flagsThe optional flags, model-dependent. See cv::ml::StatModel::Flags.
The number result.
These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.