Package org.opencv.ml
Class SVM
- java.lang.Object
- 
- org.opencv.core.Algorithm
- 
- org.opencv.ml.StatModel
- 
- org.opencv.ml.SVM
 
 
 
- 
 public class SVM extends StatModel Support Vector Machines. SEE: REF: ml_intro_svm
- 
- 
Field SummaryFields Modifier and Type Field Description static intCstatic intC_SVCstatic intCHI2static intCOEFstatic intCUSTOMstatic intDEGREEstatic intEPS_SVRstatic intGAMMAstatic intINTERstatic intLINEARstatic intNUstatic intNU_SVCstatic intNU_SVRstatic intONE_CLASSstatic intPstatic intPOLYstatic intRBFstatic intSIGMOID- 
Fields inherited from class org.opencv.ml.StatModelCOMPRESSED_INPUT, PREPROCESSED_INPUT, RAW_OUTPUT, UPDATE_MODEL
 
- 
 - 
Constructor SummaryConstructors Modifier Constructor Description protectedSVM(long addr)
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SVM__fromPtr__(long addr)static SVMcreate()Creates empty model.protected voidfinalize()doublegetC()SEE: setCMatgetClassWeights()SEE: setClassWeightsdoublegetCoef0()SEE: setCoef0doublegetDecisionFunction(int i, Mat alpha, Mat svidx)Retrieves the decision functionstatic ParamGridgetDefaultGridPtr(int param_id)Generates a grid for %SVM parameters.doublegetDegree()SEE: setDegreedoublegetGamma()SEE: setGammaintgetKernelType()Type of a %SVM kernel.doublegetNu()SEE: setNudoublegetP()SEE: setPMatgetSupportVectors()Retrieves all the support vectors The method returns all the support vectors as a floating-point matrix, where support vectors are stored as matrix rows.TermCriteriagetTermCriteria()SEE: setTermCriteriaintgetType()SEE: setTypeMatgetUncompressedSupportVectors()Retrieves all the uncompressed support vectors of a linear %SVM The method returns all the uncompressed support vectors of a linear %SVM that the compressed support vector, used for prediction, was derived from.static SVMload(java.lang.String filepath)Loads and creates a serialized svm from a file Use SVM::save to serialize and store an SVM to disk.voidsetC(double val)getC SEE: getCvoidsetClassWeights(Mat val)getClassWeights SEE: getClassWeightsvoidsetCoef0(double val)getCoef0 SEE: getCoef0voidsetDegree(double val)getDegree SEE: getDegreevoidsetGamma(double val)getGamma SEE: getGammavoidsetKernel(int kernelType)Initialize with one of predefined kernels.voidsetNu(double val)getNu SEE: getNuvoidsetP(double val)getP SEE: getPvoidsetTermCriteria(TermCriteria val)getTermCriteria SEE: getTermCriteriavoidsetType(int val)getType SEE: getTypebooleantrainAuto(Mat samples, int layout, Mat responses)Trains an %SVM with optimal parametersbooleantrainAuto(Mat samples, int layout, Mat responses, int kFold)Trains an %SVM with optimal parametersbooleantrainAuto(Mat samples, int layout, Mat responses, int kFold, ParamGrid Cgrid)Trains an %SVM with optimal parametersbooleantrainAuto(Mat samples, int layout, Mat responses, int kFold, ParamGrid Cgrid, ParamGrid gammaGrid)Trains an %SVM with optimal parametersbooleantrainAuto(Mat samples, int layout, Mat responses, int kFold, ParamGrid Cgrid, ParamGrid gammaGrid, ParamGrid pGrid)Trains an %SVM with optimal parametersbooleantrainAuto(Mat samples, int layout, Mat responses, int kFold, ParamGrid Cgrid, ParamGrid gammaGrid, ParamGrid pGrid, ParamGrid nuGrid)Trains an %SVM with optimal parametersbooleantrainAuto(Mat samples, int layout, Mat responses, int kFold, ParamGrid Cgrid, ParamGrid gammaGrid, ParamGrid pGrid, ParamGrid nuGrid, ParamGrid coeffGrid)Trains an %SVM with optimal parametersbooleantrainAuto(Mat samples, int layout, Mat responses, int kFold, ParamGrid Cgrid, ParamGrid gammaGrid, ParamGrid pGrid, ParamGrid nuGrid, ParamGrid coeffGrid, ParamGrid degreeGrid)Trains an %SVM with optimal parametersbooleantrainAuto(Mat samples, int layout, Mat responses, int kFold, ParamGrid Cgrid, ParamGrid gammaGrid, ParamGrid pGrid, ParamGrid nuGrid, ParamGrid coeffGrid, ParamGrid degreeGrid, boolean balanced)Trains an %SVM with optimal parameters- 
Methods inherited from class org.opencv.ml.StatModelcalcError, empty, getVarCount, isClassifier, isTrained, predict, predict, predict, train, train, train
 - 
Methods inherited from class org.opencv.core.Algorithmclear, getDefaultName, getNativeObjAddr, save
 
- 
 
- 
- 
- 
Field Detail- 
CUSTOMpublic static final int CUSTOM - See Also:
- Constant Field Values
 
 - 
LINEARpublic static final int LINEAR - See Also:
- Constant Field Values
 
 - 
POLYpublic static final int POLY - See Also:
- Constant Field Values
 
 - 
RBFpublic static final int RBF - See Also:
- Constant Field Values
 
 - 
SIGMOIDpublic static final int SIGMOID - See Also:
- Constant Field Values
 
 - 
CHI2public static final int CHI2 - See Also:
- Constant Field Values
 
 - 
INTERpublic static final int INTER - See Also:
- Constant Field Values
 
 - 
Cpublic static final int C - See Also:
- Constant Field Values
 
 - 
GAMMApublic static final int GAMMA - See Also:
- Constant Field Values
 
 - 
Ppublic static final int P - See Also:
- Constant Field Values
 
 - 
NUpublic static final int NU - See Also:
- Constant Field Values
 
 - 
COEFpublic static final int COEF - See Also:
- Constant Field Values
 
 - 
DEGREEpublic static final int DEGREE - See Also:
- Constant Field Values
 
 - 
C_SVCpublic static final int C_SVC - See Also:
- Constant Field Values
 
 - 
NU_SVCpublic static final int NU_SVC - See Also:
- Constant Field Values
 
 - 
ONE_CLASSpublic static final int ONE_CLASS - See Also:
- Constant Field Values
 
 - 
EPS_SVRpublic static final int EPS_SVR - See Also:
- Constant Field Values
 
 - 
NU_SVRpublic static final int NU_SVR - See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
__fromPtr__public static SVM __fromPtr__(long addr) 
 - 
getTypepublic int getType() SEE: setType- Returns:
- automatically generated
 
 - 
setTypepublic void setType(int val) getType SEE: getType- Parameters:
- val- automatically generated
 
 - 
getGammapublic double getGamma() SEE: setGamma- Returns:
- automatically generated
 
 - 
setGammapublic void setGamma(double val) getGamma SEE: getGamma- Parameters:
- val- automatically generated
 
 - 
getCoef0public double getCoef0() SEE: setCoef0- Returns:
- automatically generated
 
 - 
setCoef0public void setCoef0(double val) getCoef0 SEE: getCoef0- Parameters:
- val- automatically generated
 
 - 
getDegreepublic double getDegree() SEE: setDegree- Returns:
- automatically generated
 
 - 
setDegreepublic void setDegree(double val) getDegree SEE: getDegree- Parameters:
- val- automatically generated
 
 - 
getCpublic double getC() SEE: setC- Returns:
- automatically generated
 
 - 
setCpublic void setC(double val) getC SEE: getC- Parameters:
- val- automatically generated
 
 - 
getNupublic double getNu() SEE: setNu- Returns:
- automatically generated
 
 - 
setNupublic void setNu(double val) getNu SEE: getNu- Parameters:
- val- automatically generated
 
 - 
getPpublic double getP() SEE: setP- Returns:
- automatically generated
 
 - 
setPpublic void setP(double val) getP SEE: getP- Parameters:
- val- automatically generated
 
 - 
getClassWeightspublic Mat getClassWeights() SEE: setClassWeights- Returns:
- automatically generated
 
 - 
setClassWeightspublic void setClassWeights(Mat val) getClassWeights SEE: getClassWeights- Parameters:
- val- automatically generated
 
 - 
getTermCriteriapublic TermCriteria getTermCriteria() SEE: setTermCriteria- Returns:
- automatically generated
 
 - 
setTermCriteriapublic void setTermCriteria(TermCriteria val) getTermCriteria SEE: getTermCriteria- Parameters:
- val- automatically generated
 
 - 
getKernelTypepublic int getKernelType() Type of a %SVM kernel. See SVM::KernelTypes. Default value is SVM::RBF.- Returns:
- automatically generated
 
 - 
setKernelpublic void setKernel(int kernelType) Initialize with one of predefined kernels. See SVM::KernelTypes.- Parameters:
- kernelType- automatically generated
 
 - 
trainAutopublic boolean trainAuto(Mat samples, int layout, Mat responses, int kFold, ParamGrid Cgrid, ParamGrid gammaGrid, ParamGrid pGrid, ParamGrid nuGrid, ParamGrid coeffGrid, ParamGrid degreeGrid, boolean balanced) Trains an %SVM with optimal parameters- Parameters:
- samples- training samples
- layout- See ml::SampleTypes.
- responses- vector of responses associated with the training samples.
- 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
- Cgrid- grid for C
- gammaGrid- grid for gamma
- pGrid- grid for p
- nuGrid- grid for nu
- coeffGrid- grid for coeff
- degreeGrid- grid for degree
- 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. The method trains the %SVM model automatically by choosing the optimal parameters C, gamma, p, nu, coef0, degree. Parameters are considered optimal when the cross-validation estimate of the test set error is minimal. This function only makes use of SVM::getDefaultGrid for parameter optimization and thus only offers rudimentary parameter options. This function works for the classification (SVM::C_SVC or SVM::NU_SVC) as well as for the regression (SVM::EPS_SVR or SVM::NU_SVR). If it is SVM::ONE_CLASS, no optimization is made and the usual %SVM with parameters specified in params is executed.
- Returns:
- automatically generated
 
 - 
trainAutopublic boolean trainAuto(Mat samples, int layout, Mat responses, int kFold, ParamGrid Cgrid, ParamGrid gammaGrid, ParamGrid pGrid, ParamGrid nuGrid, ParamGrid coeffGrid, ParamGrid degreeGrid) Trains an %SVM with optimal parameters- Parameters:
- samples- training samples
- layout- See ml::SampleTypes.
- responses- vector of responses associated with the training samples.
- 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
- Cgrid- grid for C
- gammaGrid- grid for gamma
- pGrid- grid for p
- nuGrid- grid for nu
- coeffGrid- grid for coeff
- degreeGrid- grid for degree balanced cross-validation subsets that is proportions between classes in subsets are close to such proportion in the whole train dataset. The method trains the %SVM model automatically by choosing the optimal parameters C, gamma, p, nu, coef0, degree. Parameters are considered optimal when the cross-validation estimate of the test set error is minimal. This function only makes use of SVM::getDefaultGrid for parameter optimization and thus only offers rudimentary parameter options. This function works for the classification (SVM::C_SVC or SVM::NU_SVC) as well as for the regression (SVM::EPS_SVR or SVM::NU_SVR). If it is SVM::ONE_CLASS, no optimization is made and the usual %SVM with parameters specified in params is executed.
- Returns:
- automatically generated
 
 - 
trainAutopublic boolean trainAuto(Mat samples, int layout, Mat responses, int kFold, ParamGrid Cgrid, ParamGrid gammaGrid, ParamGrid pGrid, ParamGrid nuGrid, ParamGrid coeffGrid) Trains an %SVM with optimal parameters- Parameters:
- samples- training samples
- layout- See ml::SampleTypes.
- responses- vector of responses associated with the training samples.
- 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
- Cgrid- grid for C
- gammaGrid- grid for gamma
- pGrid- grid for p
- nuGrid- grid for nu
- coeffGrid- grid for coeff balanced cross-validation subsets that is proportions between classes in subsets are close to such proportion in the whole train dataset. The method trains the %SVM model automatically by choosing the optimal parameters C, gamma, p, nu, coef0, degree. Parameters are considered optimal when the cross-validation estimate of the test set error is minimal. This function only makes use of SVM::getDefaultGrid for parameter optimization and thus only offers rudimentary parameter options. This function works for the classification (SVM::C_SVC or SVM::NU_SVC) as well as for the regression (SVM::EPS_SVR or SVM::NU_SVR). If it is SVM::ONE_CLASS, no optimization is made and the usual %SVM with parameters specified in params is executed.
- Returns:
- automatically generated
 
 - 
trainAutopublic boolean trainAuto(Mat samples, int layout, Mat responses, int kFold, ParamGrid Cgrid, ParamGrid gammaGrid, ParamGrid pGrid, ParamGrid nuGrid) Trains an %SVM with optimal parameters- Parameters:
- samples- training samples
- layout- See ml::SampleTypes.
- responses- vector of responses associated with the training samples.
- 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
- Cgrid- grid for C
- gammaGrid- grid for gamma
- pGrid- grid for p
- nuGrid- grid for nu balanced cross-validation subsets that is proportions between classes in subsets are close to such proportion in the whole train dataset. The method trains the %SVM model automatically by choosing the optimal parameters C, gamma, p, nu, coef0, degree. Parameters are considered optimal when the cross-validation estimate of the test set error is minimal. This function only makes use of SVM::getDefaultGrid for parameter optimization and thus only offers rudimentary parameter options. This function works for the classification (SVM::C_SVC or SVM::NU_SVC) as well as for the regression (SVM::EPS_SVR or SVM::NU_SVR). If it is SVM::ONE_CLASS, no optimization is made and the usual %SVM with parameters specified in params is executed.
- Returns:
- automatically generated
 
 - 
trainAutopublic boolean trainAuto(Mat samples, int layout, Mat responses, int kFold, ParamGrid Cgrid, ParamGrid gammaGrid, ParamGrid pGrid) Trains an %SVM with optimal parameters- Parameters:
- samples- training samples
- layout- See ml::SampleTypes.
- responses- vector of responses associated with the training samples.
- 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
- Cgrid- grid for C
- gammaGrid- grid for gamma
- pGrid- grid for p balanced cross-validation subsets that is proportions between classes in subsets are close to such proportion in the whole train dataset. The method trains the %SVM model automatically by choosing the optimal parameters C, gamma, p, nu, coef0, degree. Parameters are considered optimal when the cross-validation estimate of the test set error is minimal. This function only makes use of SVM::getDefaultGrid for parameter optimization and thus only offers rudimentary parameter options. This function works for the classification (SVM::C_SVC or SVM::NU_SVC) as well as for the regression (SVM::EPS_SVR or SVM::NU_SVR). If it is SVM::ONE_CLASS, no optimization is made and the usual %SVM with parameters specified in params is executed.
- Returns:
- automatically generated
 
 - 
trainAutopublic boolean trainAuto(Mat samples, int layout, Mat responses, int kFold, ParamGrid Cgrid, ParamGrid gammaGrid) Trains an %SVM with optimal parameters- Parameters:
- samples- training samples
- layout- See ml::SampleTypes.
- responses- vector of responses associated with the training samples.
- 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
- Cgrid- grid for C
- gammaGrid- grid for gamma balanced cross-validation subsets that is proportions between classes in subsets are close to such proportion in the whole train dataset. The method trains the %SVM model automatically by choosing the optimal parameters C, gamma, p, nu, coef0, degree. Parameters are considered optimal when the cross-validation estimate of the test set error is minimal. This function only makes use of SVM::getDefaultGrid for parameter optimization and thus only offers rudimentary parameter options. This function works for the classification (SVM::C_SVC or SVM::NU_SVC) as well as for the regression (SVM::EPS_SVR or SVM::NU_SVR). If it is SVM::ONE_CLASS, no optimization is made and the usual %SVM with parameters specified in params is executed.
- Returns:
- automatically generated
 
 - 
trainAutopublic boolean trainAuto(Mat samples, int layout, Mat responses, int kFold, ParamGrid Cgrid) Trains an %SVM with optimal parameters- Parameters:
- samples- training samples
- layout- See ml::SampleTypes.
- responses- vector of responses associated with the training samples.
- 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
- Cgrid- grid for C balanced cross-validation subsets that is proportions between classes in subsets are close to such proportion in the whole train dataset. The method trains the %SVM model automatically by choosing the optimal parameters C, gamma, p, nu, coef0, degree. Parameters are considered optimal when the cross-validation estimate of the test set error is minimal. This function only makes use of SVM::getDefaultGrid for parameter optimization and thus only offers rudimentary parameter options. This function works for the classification (SVM::C_SVC or SVM::NU_SVC) as well as for the regression (SVM::EPS_SVR or SVM::NU_SVR). If it is SVM::ONE_CLASS, no optimization is made and the usual %SVM with parameters specified in params is executed.
- Returns:
- automatically generated
 
 - 
trainAutopublic boolean trainAuto(Mat samples, int layout, Mat responses, int kFold) Trains an %SVM with optimal parameters- Parameters:
- samples- training samples
- layout- See ml::SampleTypes.
- responses- vector of responses associated with the training samples.
- 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 balanced cross-validation subsets that is proportions between classes in subsets are close to such proportion in the whole train dataset. The method trains the %SVM model automatically by choosing the optimal parameters C, gamma, p, nu, coef0, degree. Parameters are considered optimal when the cross-validation estimate of the test set error is minimal. This function only makes use of SVM::getDefaultGrid for parameter optimization and thus only offers rudimentary parameter options. This function works for the classification (SVM::C_SVC or SVM::NU_SVC) as well as for the regression (SVM::EPS_SVR or SVM::NU_SVR). If it is SVM::ONE_CLASS, no optimization is made and the usual %SVM with parameters specified in params is executed.
- Returns:
- automatically generated
 
 - 
trainAutopublic boolean trainAuto(Mat samples, int layout, Mat responses) Trains an %SVM with optimal parameters- Parameters:
- samples- training samples
- layout- See ml::SampleTypes.
- responses- vector of responses associated with the training samples. subset is used to test the model, the others form the train set. So, the %SVM algorithm is balanced cross-validation subsets that is proportions between classes in subsets are close to such proportion in the whole train dataset. The method trains the %SVM model automatically by choosing the optimal parameters C, gamma, p, nu, coef0, degree. Parameters are considered optimal when the cross-validation estimate of the test set error is minimal. This function only makes use of SVM::getDefaultGrid for parameter optimization and thus only offers rudimentary parameter options. This function works for the classification (SVM::C_SVC or SVM::NU_SVC) as well as for the regression (SVM::EPS_SVR or SVM::NU_SVR). If it is SVM::ONE_CLASS, no optimization is made and the usual %SVM with parameters specified in params is executed.
- Returns:
- automatically generated
 
 - 
getSupportVectorspublic Mat getSupportVectors() Retrieves all the support vectors The method returns all the support vectors as a floating-point matrix, where support vectors are stored as matrix rows.- Returns:
- automatically generated
 
 - 
getUncompressedSupportVectorspublic Mat getUncompressedSupportVectors() Retrieves all the uncompressed support vectors of a linear %SVM The method returns all the uncompressed support vectors of a linear %SVM that the compressed support vector, used for prediction, was derived from. They are returned in a floating-point matrix, where the support vectors are stored as matrix rows.- Returns:
- automatically generated
 
 - 
getDecisionFunctionpublic double getDecisionFunction(int i, Mat alpha, Mat svidx)Retrieves the decision function- Parameters:
- 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.
- 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.
- 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. The method returns rho parameter of the decision function, a scalar subtracted from the weighted sum of kernel responses.
- Returns:
- automatically generated
 
 - 
getDefaultGridPtrpublic static ParamGrid getDefaultGridPtr(int param_id) Generates a grid for %SVM parameters.- Parameters:
- param_id- %SVM parameters IDs that must be one of the SVM::ParamTypes. The grid is generated for the parameter with this ID. The function generates a grid pointer for the specified parameter of the %SVM algorithm. The grid may be passed to the function SVM::trainAuto.
- Returns:
- automatically generated
 
 - 
createpublic static SVM 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.- Returns:
- automatically generated
 
 - 
loadpublic static SVM load(java.lang.String filepath) 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.- Parameters:
- filepath- path to serialized svm
- Returns:
- automatically generated
 
 
- 
 
-