Table of Contents

Class SVM

Namespace
Emgu.CV.ML
Assembly
Emgu.CV.dll

Support Vector Machine

public class SVM : UnmanagedObject, IDisposable, IStatModel, IAlgorithm
Inheritance
SVM
Implements
Inherited Members
Extension Methods

Constructors

SVM()

Create a support Vector Machine

public SVM()

Properties

C

Parameter C of a SVM optimization problem

public double C { get; set; }

Property Value

double

Coef0

Parameter coef0 of a kernel function

public double Coef0 { get; set; }

Property Value

double

Degree

Parameter degree of a kernel function

public double Degree { get; set; }

Property Value

double

Gamma

Parameter gamma of a kernel function

public double Gamma { get; set; }

Property Value

double

KernelType

Type of a SVM kernel

public SVM.SvmKernelType KernelType { get; }

Property Value

SVM.SvmKernelType

Nu

Parameter nu of a SVM optimization problem

public double Nu { get; set; }

Property Value

double

P

Parameter epsilon of a SVM optimization problem

public double P { get; set; }

Property Value

double

TermCriteria

Termination criteria of the iterative SVM training procedure which solves a partial case of constrained quadratic optimization problem

public MCvTermCriteria TermCriteria { get; set; }

Property Value

MCvTermCriteria

Type

Type of a SVM formulation

public SVM.SvmType Type { get; set; }

Property Value

SVM.SvmType

Methods

DisposeObject()

Release all the memory associated with the SVM

protected override void DisposeObject()

GetDefaultGrid(ParamType)

Get the default parameter grid for the specific SVM type

public static MCvParamGrid GetDefaultGrid(SVM.ParamType type)

Parameters

type SVM.ParamType

The SVM type

Returns

MCvParamGrid

The default parameter grid for the specific SVM type

GetSupportVectors()

Retrieves all the support vectors.

public Mat GetSupportVectors()

Returns

Mat

All the support vector as floating-point matrix, where support vectors are stored as matrix rows.

SetKernel(SvmKernelType)

Initialize with one of predefined kernels

public void SetKernel(SVM.SvmKernelType value)

Parameters

value SVM.SvmKernelType

The value

TrainAuto(TrainData, int)

The method trains the SVM model automatically by choosing the optimal parameters C, gamma, p, nu, coef0, degree from CvSVMParams. By the optimality one mean that the cross-validation estimate of the test set error is minimal.

public bool TrainAuto(TrainData trainData, int kFold = 10)

Parameters

trainData TrainData

The training data.

kFold int

Cross-validation parameter. The training set is divided into k_fold subsets, one subset being used to train the model, the others forming the test set. So, the SVM algorithm is executed k_fold times

Returns

bool

True if training is successful.

TrainAuto(TrainData, int, MCvParamGrid, MCvParamGrid, MCvParamGrid, MCvParamGrid, MCvParamGrid, MCvParamGrid, bool)

The method trains the SVM model automatically by choosing the optimal parameters C, gamma, p, nu, coef0, degree from CvSVMParams. By the optimality one mean that the cross-validation estimate of the test set error is minimal.

public bool TrainAuto(TrainData trainData, int kFold, MCvParamGrid cGrid, MCvParamGrid gammaGrid, MCvParamGrid pGrid, MCvParamGrid nuGrid, MCvParamGrid coefGrid, MCvParamGrid degreeGrid, bool balanced = false)

Parameters

trainData TrainData

The training data.

kFold int

Cross-validation parameter. The training set is divided into k_fold subsets, one subset being used to train the model, the others forming the test set. So, the SVM algorithm is executed k_fold times

cGrid MCvParamGrid

cGrid

gammaGrid MCvParamGrid

grid for gamma

pGrid MCvParamGrid

grid for p

nuGrid MCvParamGrid

grid for nu

coefGrid MCvParamGrid

grid for coeff

degreeGrid MCvParamGrid

grid for degree

balanced bool

If true and the problem is 2-class classification then the method creates more balanced cross-validation subsets that is proportions between classes in subsets are close to such proportion in the whole train dataset.

Returns

bool

True if training is successful.