SVMSGD class

Stochastic Gradient Descent SVM classifier.

A linear two-class classifier. The responses of the negative class must be < 0 (use -1 and 1): responses >= 0 count as positive, and without any negative response training succeeds but yields a constant model that predicts 1. https://docs.opencv.org/4.x/d3/d14/classcv_1_1ml_1_1SVMSGD.html

Inheritance
Available extensions

Constructors

SVMSGD.create()
Creates an empty model. Use one of the train methods to train it, or SVMSGD.load.
factory
SVMSGD.fromPointer(SVMSGDPtr ptr, [bool attach = true])
factory
SVMSGD.load(String filepath)
Loads a model saved with save from filepath. Throws CvException when the file does not hold a valid model.
factory
SVMSGD.loadFromString(String strModel, {String objname = ''})
Loads a model from the content of a file saved with save (e.g. a Flutter asset).
factory

Properties

defaultName → String
The name used when saving the model, opencv_ml_svmsgd.
no setter
hashCode → int
The hash code for this object.
no setterinherited
initialStepSize ↔ double
Parameter initialStepSize of a SVMSGD optimization problem.
getter/setter pair
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
marginRegularization ↔ double
Parameter marginRegularization of a SVMSGD optimization problem.
getter/setter pair
marginType ↔ int
Margin type, one of SOFT_MARGIN, HARD_MARGIN.
getter/setter pair
props → List<Object?>
no setterinherited
ptr ↔ Pointer<SVMSGD>
getter/setter pairinherited
ref → SVMSGD
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
shift → double
The shift of the trained model (decision function f(x) = weights * x + shift).
no setter
stepDecreasingPower ↔ double
Parameter stepDecreasingPower of a SVMSGD optimization problem.
getter/setter pair
svmsgdType ↔ int
Algorithm type, one of SGD, ASGD.
getter/setter pair
termCriteria ↔ TermCriteria
Termination criteria of the training algorithm.
getter/setter pair
varCount → int
Number of variables in training samples.
no setter
weights → Mat
The weights of the trained model (decision function f(x) = weights * x + shift).
no setter

Methods

calcError(TrainData data, bool test) → (double, Mat)
Computes the error on the training (test false) or test (test true) part of data.
calcErrorAsync(TrainData data, bool test) → Future<(double, Mat)>

Available on SVMSGD, provided by the SVMSGDAsync extension

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

Available on SVMSGD, provided by the SVMSGDAsync extension

save(String filename) → void
Saves the model to filename (.xml, .yml or .json).
setOptimalParameters({int svmsgdType = ASGD, int marginType = SOFT_MARGIN}) → void
Sets the recommended parameters for the given algorithm and margin type.
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>

Available on SVMSGD, provided by the SVMSGDAsync extension

trainWithData(TrainData data, {int flags = 0}) → bool
Trains the model on data, flags may be StatModel.UPDATE_MODEL or model-specific flags.
trainWithDataAsync(TrainData data, {int flags = 0}) → Future<bool>

Available on SVMSGD, provided by the SVMSGDAsync extension

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

finalizer → NativeFinalizer
final

Constants

ASGD → const int
HARD_MARGIN → const int
SGD → const int
SOFT_MARGIN → const int