train_class_svmT_train_class_svmTrainClassSvmTrainClassSvmtrain_class_svm (Operator)


train_class_svmT_train_class_svmTrainClassSvmTrainClassSvmtrain_class_svm — Train a support vector machine.


train_class_svm( : : SVMHandle, Epsilon, TrainMode : )

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

void TrainClassSvm(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)

static void HOperatorSet.TrainClassSvm(HTuple SVMHandle, HTuple epsilon, HTuple trainMode)

void HClassSvm.TrainClassSvm(double epsilon, HTuple trainMode)

void HClassSvm.TrainClassSvm(double epsilon, string trainMode)

def train_class_svm(svmhandle: HHandle, epsilon: float, train_mode: Union[str, int]) -> None


train_class_svmtrain_class_svmTrainClassSvmTrainClassSvmTrainClassSvmtrain_class_svm trains the support vector machine (SVM) given in SVMHandleSVMHandleSVMHandleSVMHandleSVMHandlesvmhandle. 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_svmadd_sample_class_svmAddSampleClassSvmAddSampleClassSvmAddSampleClassSvmadd_sample_class_svm or read_samples_class_svmread_samples_class_svmReadSamplesClassSvmReadSamplesClassSvmReadSamplesClassSvmread_samples_class_svm.

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 EpsilonEpsilonEpsilonEpsilonepsilonepsilon. By default, a value of 0.001 should be used for EpsilonEpsilonEpsilonEpsilonepsilonepsilon 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.001 might be chosen. There are two common reasons for changing EpsilonEpsilonEpsilonEpsilonepsilonepsilon: First, if you specified a very small value for NuNuNuNununu when calling (create_class_svmcreate_class_svmCreateClassSvmCreateClassSvmCreateClassSvmcreate_class_svm), e.g., NuNuNuNununu = 0.001, a smaller EpsilonEpsilonEpsilonEpsilonepsilonepsilon might significantly improve the recognition rate. A second case is the determination of the optimal kernel function and its parametrization (e.g., the KernelParamKernelParamKernelParamKernelParamkernelParamkernel_param-NuNuNuNununu pair for the RBF kernel) with the computationally intensive n-fold cross validation. Here, choosing a bigger EpsilonEpsilonEpsilonEpsilonepsilonepsilon reduces the computational time without changing the parameters of the optimal kernel that would be obtained when using the default EpsilonEpsilonEpsilonEpsilonepsilonepsilon. After the optimal KernelParamKernelParamKernelParamKernelParamkernelParamkernel_param-NuNuNuNununu pair is obtained, the final training is conducted with a small EpsilonEpsilonEpsilonEpsilonepsilonepsilon.

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

With the parameter TrainModeTrainModeTrainModeTrainModetrainModetrain_mode you can choose between different training modes. Normally, you train an SVM without additional information and TrainModeTrainModeTrainModeTrainModetrainModetrain_mode is set to 'default'"default""default""default""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 TrainModeTrainModeTrainModeTrainModetrainModetrain_mode a SVM handle of a previously trained SVM is passed. Note that the SVM handle passed in SVMHandleSVMHandleSVMHandleSVMHandleSVMHandlesvmhandle and the SVMHandle passed in TrainModeTrainModeTrainModeTrainModetrainModetrain_mode must have the same training data, the same mode and the same number of classes (see create_class_svmcreate_class_svmCreateClassSvmCreateClassSvmCreateClassSvmcreate_class_svm). 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 TrainModeTrainModeTrainModeTrainModetrainModetrain_mode = 'add_sv_to_train_set'"add_sv_to_train_set""add_sv_to_train_set""add_sv_to_train_set""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_svmtrain_class_svmTrainClassSvmTrainClassSvmTrainClassSvmtrain_class_svm 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 TrainModeTrainModeTrainModeTrainModetrainModetrain_mode = 'default'"default""default""default""default""default". Afterwards, the previous training set is removed with clear_samples_class_svmclear_samples_class_svmClearSamplesClassSvmClearSamplesClassSvmClearSamplesClassSvmclear_samples_class_svm, the next chunk is added with add_sample_class_svmadd_sample_class_svmAddSampleClassSvmAddSampleClassSvmAddSampleClassSvmadd_sample_class_svm and trained with TrainModeTrainModeTrainModeTrainModetrainModetrain_mode = 'add_sv_to_train_set'"add_sv_to_train_set""add_sv_to_train_set""add_sv_to_train_set""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_svmcreate_class_svmCreateClassSvmCreateClassSvmCreateClassSvmcreate_class_svm) is not changed when training with TrainModeTrainModeTrainModeTrainModetrainModetrain_mode = 'add_sv_to_train_set'"add_sv_to_train_set""add_sv_to_train_set""add_sv_to_train_set""add_sv_to_train_set""add_sv_to_train_set".

Execution Information

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.


SVMHandleSVMHandleSVMHandleSVMHandleSVMHandlesvmhandle (input_control, state is modified)  class_svm HClassSvm, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)

SVM handle.

EpsilonEpsilonEpsilonEpsilonepsilonepsilon (input_control)  real HTuplefloatHTupleHtuple (real) (double) (double) (double)

Stop parameter for training.

Default value: 0.001

Suggested values: 0.00001, 0.0001, 0.001, 0.01, 0.1

TrainModeTrainModeTrainModeTrainModetrainModetrain_mode (input_control)  number HTupleUnion[str, int]HTupleHtuple (string / integer) (string / int / long) (HString / Hlong) (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 value: 'default' "default" "default" "default" "default" "default"

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

Example (HDevelop)

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


If the parameters are valid the operator train_class_svmtrain_class_svmTrainClassSvmTrainClassSvmTrainClassSvmtrain_class_svm returns the value TRUE. If necessary, an exception is raised.

Possible Predecessors

add_sample_class_svmadd_sample_class_svmAddSampleClassSvmAddSampleClassSvmAddSampleClassSvmadd_sample_class_svm, read_samples_class_svmread_samples_class_svmReadSamplesClassSvmReadSamplesClassSvmReadSamplesClassSvmread_samples_class_svm

Possible Successors

classify_class_svmclassify_class_svmClassifyClassSvmClassifyClassSvmClassifyClassSvmclassify_class_svm, write_class_svmwrite_class_svmWriteClassSvmWriteClassSvmWriteClassSvmwrite_class_svm, create_class_lut_svmcreate_class_lut_svmCreateClassLutSvmCreateClassLutSvmCreateClassLutSvmcreate_class_lut_svm


train_dl_classifier_batchtrain_dl_classifier_batchTrainDlClassifierBatchTrainDlClassifierBatchTrainDlClassifierBatchtrain_dl_classifier_batch, read_class_svmread_class_svmReadClassSvmReadClassSvmReadClassSvmread_class_svm

See also



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.