SVM class
Support Vector Machines. https://docs.opencv.org/4.x/d1/d2d/classcv_1_1ml_1_1SVM.html
Constructors
- SVM.create()
-
Creates an empty model. Use one of the train methods to train it, or SVM.load.
factory
- SVM.fromPointer(SVMPtr ptr, [bool attach = true])
-
factory
- SVM.load(String filepath)
-
Loads a model saved with save from
filepath. Throws CvException when the file does not hold a valid model.factory - SVM.loadFromString(String strModel, {String objname = ''})
-
Loads a model from the content of a file saved with save (e.g. a Flutter asset).
factory
Properties
- C ↔ double
-
Parameter C of a SVM optimization problem.
getter/setter pair
- classWeights ↔ Mat
-
Optional weights in the C_SVC problem, assigned to particular classes.
getter/setter pair
- coef0 ↔ double
-
Parameter coef0 of a kernel function.
getter/setter pair
- defaultName → String
-
The name used when saving the model,
opencv_ml_svm.no setter - degree ↔ double
-
Parameter degree of a kernel function.
getter/setter pair
- gamma ↔ double
-
Parameter gamma of a kernel function.
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- isClassifier → bool
-
Whether the model is a classifier (false for a regressor).
no setter
- isDisposed → bool
-
Whether this object has been disposed.
no setterinherited
- isEmpty → bool
-
no setter
- isTrained → bool
-
no setter
- kernelType ↔ int
-
Type of a SVM kernel, one of LINEAR, POLY, RBF, SIGMOID, CHI2, INTER.
getter/setter pair
- nu ↔ double
-
Parameter nu of a SVM optimization problem.
getter/setter pair
- p ↔ double
-
Parameter epsilon of a SVM optimization problem.
getter/setter pair
-
props
→ List<
Object?> -
no setterinherited
-
ptr
↔ Pointer<
SVM> -
getter/setter pairinherited
- ref → SVM
-
A view of the native memory behind ptr, not a copy.
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- supportVectors → Mat
-
All the support vectors, compressed for a linear kernel.
no setter
- termCriteria ↔ TermCriteria
-
Termination criteria of the training algorithm.
getter/setter pair
- type ↔ int
-
Type of a SVM formulation, one of C_SVC, NU_SVC, ONE_CLASS, EPS_SVR, NU_SVR.
getter/setter pair
- uncompressedSupportVectors → Mat
-
All the uncompressed support vectors of a linear SVM.
no setter
- varCount → int
-
Number of variables in training samples.
no setter
Methods
-
calcError(
TrainData data, bool test) → (double, Mat) -
Computes the error on the training (
testfalse) or test (testtrue) part ofdata. -
calcErrorAsync(
TrainData data, bool test) → Future< (double, Mat)> -
clear(
) → void - Clears the model, it becomes untrained.
-
dispose(
) → void -
Releases the underlying native resources. Idempotent: calling it more
than once is safe, but the object must not be used after dispose.
inherited
-
freeNative(
) → void -
Frees the native resources owned by this object. Subclasses implement the
concrete free logic here; callers must use dispose instead.
override
-
getDecisionFunction(
int i) → (double, Mat, Mat) -
Retrieves the decision function
i. -
getDecisionFunctionAsync(
int i) → Future< (double, Mat, Mat)> -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
predict(
Mat samples, {int flags = 0}) → Mat -
Predicts the response for each row of
samples, one row of the returned Mat per sample. -
predictAsync(
Mat samples, {int flags = 0}) → Future< Mat> -
save(
String filename) → void -
Saves the model to
filename(.xml, .yml or .json). -
toString(
) → String -
A string representation of this object.
inherited
-
train(
Mat samples, int layout, Mat responses) → bool -
Trains the model on
samples(CV_32F, one sample per row for ROW_SAMPLE). -
trainAsync(
Mat samples, int layout, Mat responses) → Future< bool> -
trainAuto(
TrainData data, {int kFold = 10, ParamGrid? Cgrid, ParamGrid? gammaGrid, ParamGrid? pGrid, ParamGrid? nuGrid, ParamGrid? coeffGrid, ParamGrid? degreeGrid, bool balanced = false}) → bool -
Trains the SVM with the optimal parameters found by a
kFoldcross-validation over the grids, a grid leftnulluses getDefaultGrid. -
trainAutoAsync(
TrainData data, {int kFold = 10, ParamGrid? Cgrid, ParamGrid? gammaGrid, ParamGrid? pGrid, ParamGrid? nuGrid, ParamGrid? coeffGrid, ParamGrid? degreeGrid, bool balanced = false}) → Future< bool> -
trainWithData(
TrainData data, {int flags = 0}) → bool -
Trains the model on
data,flagsmay be StatModel.UPDATE_MODEL or model-specific flags. -
trainWithDataAsync(
TrainData data, {int flags = 0}) → Future< bool>
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- finalizer → NativeFinalizer
-
final
Static Methods
-
getDefaultGrid(
int paramId) → ParamGrid -
The default grid of the SVM parameter
paramId, one of PARAM_C .. PARAM_DEGREE.
Constants
- C_SVC → const int
- CHI2 → const int
- CUSTOM → const int
- EPS_SVR → const int
- INTER → const int
- LINEAR → const int
- NU_SVC → const int
- NU_SVR → const int
- ONE_CLASS → const int
- PARAM_C → const int
- PARAM_COEF → const int
- PARAM_DEGREE → const int
- PARAM_GAMMA → const int
- PARAM_NU → const int
- PARAM_P → const int
- POLY → const int
- RBF → const int
- SIGMOID → const int