Show / Hide Table of Contents

Class SVM

Support Vector Machines

Inheritance
System.Object
DisposableObject
DisposableCvObject
Algorithm
StatModel
SVM
Implements
ICvPtrHolder
Inherited Members
StatModel.GetVarCount()
StatModel.Empty()
StatModel.IsTrained()
StatModel.IsClassifier()
StatModel.Train(TrainData, Int32)
StatModel.Train(InputArray, SampleTypes, InputArray)
StatModel.CalcError(TrainData, Boolean, OutputArray)
StatModel.Predict(InputArray, OutputArray, StatModel.Flags)
Algorithm.Write(FileStorage)
Algorithm.Read(FileNode)
Algorithm.Save(String)
Algorithm.GetDefaultName()
DisposableCvObject.ptr
DisposableCvObject.CvPtr
DisposableObject.DataHandle
DisposableObject.IsDisposed
DisposableObject.IsEnabledDispose
DisposableObject.AllocatedMemory
DisposableObject.AllocatedMemorySize
DisposableObject.Dispose()
DisposableObject.Dispose(Boolean)
DisposableObject.AllocGCHandle(Object)
DisposableObject.AllocMemory(Int32)
DisposableObject.NotifyMemoryPressure(Int64)
DisposableObject.ThrowIfDisposed()
Namespace: OpenCvSharp.ML
Assembly: OpenCvSharp.dll
Syntax
public class SVM : StatModel, ICvPtrHolder

Constructors

| Improve this Doc View Source

SVM(IntPtr)

Creates instance by raw pointer cv::ml::SVM*

Declaration
protected SVM(IntPtr p)
Parameters
Type Name Description
IntPtr p

Properties

| Improve this Doc View Source

C

Parameter C of a %SVM optimization problem. For SVM::C_SVC, SVM::EPS_SVR or SVM::NU_SVR. Default value is 0.

Declaration
public double C { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

ClassWeights

Optional weights in the SVM::C_SVC problem, assigned to particular classes.

Declaration
public Mat ClassWeights { get; set; }
Property Value
Type Description
Mat
Remarks

They are multiplied by C so the parameter C of class i becomes classWeights(i) * C. Thus these weights affect the misclassification penalty for different classes. The larger weight, the larger penalty on misclassification of data from the corresponding class. Default value is empty Mat.

| Improve this Doc View Source

Coef0

Parameter coef0 of a kernel function. For SVM::POLY or SVM::SIGMOID. Default value is 0.

Declaration
public double Coef0 { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

Degree

Parameter degree of a kernel function. For SVM::POLY. Default value is 0.

Declaration
public double Degree { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

Gamma

Parameter gamma of a kernel function. For SVM::POLY, SVM::RBF, SVM::SIGMOID or SVM::CHI2. Default value is 1.

Declaration
public double Gamma { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

KernelType

Type of a %SVM kernel. See SVM::KernelTypes. Default value is SVM::RBF.

Declaration
public SVM.KernelTypes KernelType { get; set; }
Property Value
Type Description
SVM.KernelTypes
| Improve this Doc View Source

Nu

Parameter nu of a %SVM optimization problem. For SVM::NU_SVC, SVM::ONE_CLASS or SVM::NU_SVR. Default value is 0.

Declaration
public double Nu { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

P

Parameter epsilon of a %SVM optimization problem. For SVM::EPS_SVR. Default value is 0.

Declaration
public double P { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

TermCriteria

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

Declaration
public TermCriteria TermCriteria { get; set; }
Property Value
Type Description
OpenCvSharp.TermCriteria
Remarks

You can specify tolerance and/or the maximum number of iterations. Default value is TermCriteria( TermCriteria::MAX_ITER + TermCriteria::EPS, 1000, FLT_EPSILON );

| Improve this Doc View Source

Type

Type of a %SVM formulation. Default value is SVM::C_SVC.

Declaration
public SVM.Types Type { get; set; }
Property Value
Type Description
SVM.Types

Methods

| Improve this Doc View Source

Create()

Creates empty model. Use StatModel::Train to train the model. Since %SVM has several parameters, you may want to find the best parameters for your problem, it can be done with SVM::TrainAuto.

Declaration
public static SVM Create()
Returns
Type Description
SVM
| Improve this Doc View Source

DisposeManaged()

Releases managed resources

Declaration
protected override void DisposeManaged()
Overrides
DisposableObject.DisposeManaged()
| Improve this Doc View Source

DisposeUnmanaged()

Declaration
protected override void DisposeUnmanaged()
Overrides
DisposableCvObject.DisposeUnmanaged()
| Improve this Doc View Source

Get()

Declaration
public override IntPtr Get()
Returns
Type Description
IntPtr
| Improve this Doc View Source

GetDecisionFunction(Int32, OutputArray, OutputArray)

Retrieves the decision function

Declaration
public double GetDecisionFunction(int i, OutputArray alpha, OutputArray svidx)
Parameters
Type Name Description
System.Int32 i

i the index of the decision function. If the problem solved is regression, 1-class or 2-class classification, then there will be just one decision function and the index should always be 0. Otherwise, in the case of N-class classification, there will be N(N-1)/2 decision functions.

OutputArray alpha

alpha the optional output vector for weights, corresponding to different support vectors. In the case of linear %SVM all the alpha's will be 1's.

OutputArray svidx

the optional output vector of indices of support vectors within the matrix of support vectors (which can be retrieved by SVM::getSupportVectors). In the case of linear %SVM each decision function consists of a single "compressed" support vector.

Returns
Type Description
System.Double
| Improve this Doc View Source

GetDefaultGrid(SVM.ParamTypes)

Generates a grid for SVM parameters.

Declaration
public static ParamGrid GetDefaultGrid(SVM.ParamTypes paramId)
Parameters
Type Name Description
SVM.ParamTypes paramId

SVM parameters IDs that must be one of the SVM::ParamTypes. The grid is generated for the parameter with this ID.

Returns
Type Description
ParamGrid
| Improve this Doc View Source

GetSupportVectors()

Retrieves all the support vectors

Declaration
public Mat GetSupportVectors()
Returns
Type Description
Mat
| Improve this Doc View Source

Load(String)

Loads and creates a serialized svm from a file. Use SVM::save to serialize and store an SVM to disk. Load the SVM from this file again, by calling this function with the path to the file.

Declaration
public static SVM Load(string filePath)
Parameters
Type Name Description
System.String filePath
Returns
Type Description
SVM
| Improve this Doc View Source

LoadFromString(String)

Loads algorithm from a String.

Declaration
public static SVM LoadFromString(string strModel)
Parameters
Type Name Description
System.String strModel

The string variable containing the model you want to load.

Returns
Type Description
SVM
| Improve this Doc View Source

TrainAuto(TrainData, Int32, Nullable<ParamGrid>, Nullable<ParamGrid>, Nullable<ParamGrid>, Nullable<ParamGrid>, Nullable<ParamGrid>, Nullable<ParamGrid>, Boolean)

Trains an %SVM with optimal parameters.

Declaration
public bool TrainAuto(TrainData data, int kFold = 10, ParamGrid? cGrid = null, ParamGrid? gammaGrid = null, ParamGrid? pGrid = null, ParamGrid? nuGrid = null, ParamGrid? coeffGrid = null, ParamGrid? degreeGrid = null, bool balanced = false)
Parameters
Type Name Description
TrainData data

the training data that can be constructed using TrainData::create or TrainData::loadFromCSV.

System.Int32 kFold

Cross-validation parameter. The training set is divided into kFold subsets. One subset is used to test the model, the others form the train set. So, the %SVM algorithm is executed kFold times.

System.Nullable<ParamGrid> cGrid

grid for C

System.Nullable<ParamGrid> gammaGrid

grid for gamma

System.Nullable<ParamGrid> pGrid

grid for p

System.Nullable<ParamGrid> nuGrid

grid for nu

System.Nullable<ParamGrid> coeffGrid

grid for coeff

System.Nullable<ParamGrid> degreeGrid

grid for degree

System.Boolean balanced

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
Type Description
System.Boolean

Implements

ICvPtrHolder
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX