Class SVM
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
Coef0
Parameter coef0 of a kernel function
public double Coef0 { get; set; }
Property Value
Degree
Parameter degree of a kernel function
public double Degree { get; set; }
Property Value
Gamma
Parameter gamma of a kernel function
public double Gamma { get; set; }
Property Value
KernelType
Type of a SVM kernel
public SVM.SvmKernelType KernelType { get; }
Property Value
Nu
Parameter nu of a SVM optimization problem
public double Nu { get; set; }
Property Value
P
Parameter epsilon of a SVM optimization problem
public double P { get; set; }
Property Value
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
Type
Type of a SVM formulation
public SVM.SvmType Type { get; set; }
Property Value
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
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.SvmKernelTypeThe 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
TrainDataThe training data.
kFold
intCross-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
TrainDataThe training data.
kFold
intCross-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
MCvParamGridcGrid
gammaGrid
MCvParamGridgrid for gamma
pGrid
MCvParamGridgrid for p
nuGrid
MCvParamGridgrid for nu
coefGrid
MCvParamGridgrid for coeff
degreeGrid
MCvParamGridgrid for degree
balanced
boolIf 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.