- *Type of SVM*. We choose here the type @ref cv::ml::SVM::C_SVC "C_SVC" that can be used for
@endcode
n-class classification (n \f$\geq\f$ 2). The important feature of this type is that it deals
- *Type of SVM*. We choose here the type **ml::SVM::C_SVC** that can be used for n-class
with imperfect separation of classes (i.e. when the training data is non-linearly separable).
classification (n \f$\geq\f$ 2). This parameter is defined in the attribute
This feature is not important here since the data is linearly separable and we chose this SVM
*ml::SVM::Params.svmType*.
type only for being the most commonly used.
The important feature of the type of SVM **CvSVM::C_SVC** deals with imperfect separation of classes (i.e. when the training data is non-linearly separable). This feature is not important here since the data is linearly separable and we chose this SVM type only for being the most commonly used.
- *Type of SVM kernel*. We have not talked about kernel functions since they are not
- *Type of SVM kernel*. We have not talked about kernel functions since they are not
interesting for the training data we are dealing with. Nevertheless, let's explain briefly
interesting for the training data we are dealing with. Nevertheless, let's explain briefly now
now the main idea behind a kernel function. It is a mapping done to the training data to
the main idea behind a kernel function. It is a mapping done to the training data to improve
improve its resemblance to a linearly separable set of data. This mapping consists of
its resemblance to a linearly separable set of data. This mapping consists of increasing the
increasing the dimensionality of the data and is done efficiently using a kernel function.
dimensionality of the data and is done efficiently using a kernel function. We choose here the
We choose here the type **ml::SVM::LINEAR** which means that no mapping is done. This
type @ref cv::ml::SVM::LINEAR "LINEAR" which means that no mapping is done. This parameter is
parameter is defined in the attribute *ml::SVMParams.kernel_type*.
defined using cv::ml::SVM::setKernel.
- *Termination criteria of the algorithm*. The SVM training procedure is implemented solving a
- *Termination criteria of the algorithm*. The SVM training procedure is implemented solving a
constrained quadratic optimization problem in an **iterative** fashion. Here we specify a
constrained quadratic optimization problem in an **iterative** fashion. Here we specify a
maximum number of iterations and a tolerance error so we allow the algorithm to finish in
maximum number of iterations and a tolerance error so we allow the algorithm to finish in
less number of steps even if the optimal hyperplane has not been computed yet. This
less number of steps even if the optimal hyperplane has not been computed yet. This
parameter is defined in a structure @ref cv::cvTermCriteria .
parameter is defined in a structure @ref cv::TermCriteria .
-# **Train the SVM**
-# **Train the SVM**
We call the method @ref cv::ml::SVM::train to build the SVM model.
There are just two differences between the configuration we do here and the one that was done in
There are just two differences between the configuration we do here and the one that was done in
the previous tutorial (tutorial_introduction_to_svm) that we use as reference.
the previous tutorial (@ref tutorial_introduction_to_svm) that we use as reference.
- *CvSVM::C_SVC*. We chose here a small value of this parameter in order not to punish too much
- _C_. We chose here a small value of this parameter in order not to punish too much the
the misclassification errors in the optimization. The idea of doing this stems from the will
misclassification errors in the optimization. The idea of doing this stems from the will of
of obtaining a solution close to the one intuitively expected. However, we recommend to get a
obtaining a solution close to the one intuitively expected. However, we recommend to get a
better insight of the problem by making adjustments to this parameter.
better insight of the problem by making adjustments to this parameter.
@note Here there are just very few points in the overlapping region between classes, giving a smaller value to **FRAC_LINEAR_SEP** the density of points can be incremented and the impact of the parameter **CvSVM::C_SVC** explored deeply.
@note In this case there are just very few points in the overlapping region between classes.
By giving a smaller value to __FRAC_LINEAR_SEP__ the density of points can be incremented and the
impact of the parameter _C_ explored deeply.
- *Termination Criteria of the algorithm*. The maximum number of iterations has to be
- _Termination Criteria of the algorithm_. The maximum number of iterations has to be
increased considerably in order to solve correctly a problem with non-linearly separable
increased considerably in order to solve correctly a problem with non-linearly separable
training data. In particular, we have increased in five orders of magnitude this value.
training data. In particular, we have increased in five orders of magnitude this value.
-# **Train the SVM**
-# __Train the SVM__
We call the method @ref cv::ml::SVM::train to build the SVM model. Watch out that the training
We call the method @ref cv::ml::SVM::train to build the SVM model. Watch out that the training
process may take a quite long time. Have patiance when your run the program.
process may take a quite long time. Have patiance when your run the program.