Skip to content

train_class_svmTrainClassSvmTrainClassSvmtrain_class_svmT_train_class_svm🔗

Short description🔗

train_class_svmTrainClassSvmTrainClassSvmtrain_class_svmT_train_class_svm — Train a support vector machine.

Signature🔗

train_class_svm( class_svm SVMHandle, real Epsilon, number TrainMode )void TrainClassSvm( const HTuple& SVMHandle, const HTuple& Epsilon, const HTuple& TrainMode )static void HOperatorSet.TrainClassSvm( HTuple SVMHandle, HTuple epsilon, HTuple trainMode )def train_class_svm( svmhandle: HHandle, epsilon: float, train_mode: Union[str, int] ) -> None

Herror T_train_class_svm( const Htuple SVMHandle, const Htuple Epsilon, const Htuple TrainMode )

void HClassSvm::TrainClassSvm( double Epsilon, const HTuple& TrainMode ) const

void HClassSvm::TrainClassSvm( double Epsilon, const HString& TrainMode ) const

void HClassSvm::TrainClassSvm( double Epsilon, const char* TrainMode ) const

void HClassSvm::TrainClassSvm( double Epsilon, const wchar_t* TrainMode ) const (Windows only)

void HClassSvm.TrainClassSvm( double epsilon, HTuple trainMode )

void HClassSvm.TrainClassSvm( double epsilon, string trainMode )

Description🔗

train_class_svmTrainClassSvm trains the support vector machine (SVM) given in SVMHandleSVMHandlesvmhandle. Before the SVM can be trained, the training samples to be used for the training must be added to the SVM using add_sample_class_svmAddSampleClassSvm or read_samples_class_svmReadSamplesClassSvm.

Technically, training an SVM means solving a convex quadratic optimization problem. This implies that it can be assured that training terminates after finite steps at the global optimum. In order to recognize termination, the gradient of the function that is optimized internally must fall below a threshold, which is set in Epsilonepsilonepsilon. By default, a value of 0.0010.001 should be used for Epsilonepsilonepsilon since this yields the best results in practice. A too big value leads to a too early termination and might result in suboptimal solutions. With a too small value the optimization requires a longer time, often without changing the recognition rate significantly. Nevertheless, if longer training times are possible, a smaller value than 0.0010.001 might be chosen. There are two common reasons for changing Epsilonepsilonepsilon: First, if you specified a very small value for Nununu when calling (create_class_svmCreateClassSvm), e.g., Nununu \(=\) 0.0010.001, a smaller Epsilonepsilonepsilon might significantly improve the recognition rate. A second case is the determination of the optimal kernel function and its parametrization (e.g., the KernelParamkernelParamkernel_param-Nununu pair for the RBF kernel) with the computationally intensive n-fold cross validation. Here, choosing a bigger Epsilonepsilonepsilon reduces the computational time without changing the parameters of the optimal kernel that would be obtained when using the default Epsilonepsilonepsilon. After the optimal KernelParamkernelParamkernel_param-Nununu pair is obtained, the final training is conducted with a small Epsilonepsilonepsilon.

The duration of the training depends on the training data, in particular on the number of resulting support vectors (SVs), and Epsilonepsilonepsilon. It can lie between seconds and several hours. It is therefore recommended to choose the SVM parameter Nununu in create_class_svmCreateClassSvm so that as few SVs as possible are generated without decreasing the recognition rate. Special care must be taken with the parameter Nununu in create_class_svmCreateClassSvm so that the optimization starts from a feasible region. If too many training errors are chosen with a too big Nununu, an exception is raised. In this case, an SVM with the same training data, but with smaller Nununu must be trained.

With the parameter TrainModetrainModetrain_mode you can choose between different training modes. Normally, you train an SVM without additional information and TrainModetrainModetrain_mode is set to 'default'"default". If multiple SVMs for the same data set but with different kernels are trained, subsequent training runs can reuse optimization results and thus speedup the overall training time of all runs. For this mode, in TrainModetrainModetrain_mode a SVM handle of a previously trained SVM is passed. Note that the SVM handle passed in SVMHandleSVMHandlesvmhandle and the SVMHandle passed in TrainModetrainModetrain_mode must have the same training data, the same mode and the same number of classes (see create_class_svmCreateClassSvm). The application for this training mode is the evaluation of different kernel functions given the same training set. In the literature this is referred to as alpha seeding.

With TrainModetrainModetrain_mode \(=\) 'add_sv_to_train_set'"add_sv_to_train_set" it is possible to append the support vectors that were generated by a previous call of train_class_svmTrainClassSvm to the currently saved training set. This mode has two typical application areas: First, it is possible to gradually train a SVM. For this, the complete training set is divided into disjunctive chunks. The first chunk is trained normally using TrainModetrainModetrain_mode \(=\) 'default'"default". Afterwards, the previous training set is removed with clear_samples_class_svmClearSamplesClassSvm, the next chunk is added with add_sample_class_svmAddSampleClassSvm and trained with TrainModetrainModetrain_mode \(=\) 'add_sv_to_train_set'"add_sv_to_train_set". This is repeated until all chunks are trained. This approach has the advantage that even huge training data sets can be trained efficiently with respect to memory consumption. A second application area for this mode is that a general purpose classifier can be specialized by adding characteristic training samples and then retraining it. Please note that the preprocessing (as described in create_class_svmCreateClassSvm) is not changed when training with TrainModetrainModetrain_mode \(=\) 'add_sv_to_train_set'"add_sv_to_train_set".

Execution information🔗

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Processed without parallelization.

This operator modifies the state of the following input parameter:

During execution of this operator, access to the value of this parameter must be synchronized if it is used across multiple threads.

Parameters🔗

SVMHandleSVMHandlesvmhandle (input_control, state is modified) class_svm → (handle)HTuple (HHandle)HClassSvm, HTuple (IntPtr)HHandleHtuple (handle)

SVM handle.

Epsilonepsilonepsilon (input_control) real → (real)HTuple (double)HTuple (double)floatHtuple (double)

Stop parameter for training.

Default: 0.0010.001
Suggested values: 0.00001, 0.0001, 0.001, 0.01, 0.10.00001, 0.0001, 0.001, 0.01, 0.1

TrainModetrainModetrain_mode (input_control) number → (string / integer)HTuple (HString / Hlong)HTuple (string / int / long)Union[str, int]Htuple (char* / Hlong)

Mode of training. For normal operation: ‘default’. If SVs already included in the SVM should be used for training: ‘add_sv_to_train_set’. For alpha seeding: the respective SVM handle.

Default: 'default'"default"
List of values: 'add_sv_to_train_set', 'default'"add_sv_to_train_set", "default"

Example🔗

(HDevelop)

* Train an SVM
create_class_svm (NumFeatures, 'rbf', 0.01, 0.01, NumClasses,\
                  'one-versus-all', 'normalization', NumFeatures,\
                  SVMHandle)
read_samples_class_svm (SVMHandle, 'samples.mtf')
train_class_svm (SVMHandle, 0.001, 'default')
write_class_svm (SVMHandle, 'classifier.svm')

Result🔗

If the parameters are valid the operator train_class_svmTrainClassSvm returns the value 2 (H_MSG_TRUE). If necessary, an exception is raised.

Combinations with other operators🔗

Combinations

Possible predecessors

add_sample_class_svmAddSampleClassSvm, read_samples_class_svmReadSamplesClassSvm

Possible successors

classify_class_svmClassifyClassSvm, write_class_svmWriteClassSvm, create_class_lut_svmCreateClassLutSvm

Alternatives

train_dl_model_batchTrainDlModelBatch, read_class_svmReadClassSvm

See also

create_class_svmCreateClassSvm

References🔗

John Shawe-Taylor, Nello Cristianini: ``Kernel Methods for Pattern Analysis’‘; Cambridge University Press, Cambridge; 2004.

Bernhard Schölkopf, Alexander J.Smola: “Learning with Kernels”; MIT Press, London; 1999.

Module🔗

Foundation