Multi-class Support Vector Machine

The multi-class support vector machine is a multi-class classifier which uses CLibSVM to do one vs one classification. See Kernel Support Vector Machine for more details.

Example

Imagine we have files with training and test data. We create CDenseFeatures (here 64 bit floats aka RealFeatures) and CMulticlassLabels as

features_train = RealFeatures(f_feats_train)
features_test = RealFeatures(f_feats_test)
labels_train = MulticlassLabels(f_labels_train)
labels_test = MulticlassLabels(f_labels_test)
features_train = RealFeatures(f_feats_train);
features_test = RealFeatures(f_feats_test);
labels_train = MulticlassLabels(f_labels_train);
labels_test = MulticlassLabels(f_labels_test);
RealFeatures features_train = new RealFeatures(f_feats_train);
RealFeatures features_test = new RealFeatures(f_feats_test);
MulticlassLabels labels_train = new MulticlassLabels(f_labels_train);
MulticlassLabels labels_test = new MulticlassLabels(f_labels_test);
features_train = Modshogun::RealFeatures.new f_feats_train
features_test = Modshogun::RealFeatures.new f_feats_test
labels_train = Modshogun::MulticlassLabels.new f_labels_train
labels_test = Modshogun::MulticlassLabels.new f_labels_test
features_train <- RealFeatures(f_feats_train)
features_test <- RealFeatures(f_feats_test)
labels_train <- MulticlassLabels(f_labels_train)
labels_test <- MulticlassLabels(f_labels_test)
features_train = modshogun.RealFeatures(f_feats_train)
features_test = modshogun.RealFeatures(f_feats_test)
labels_train = modshogun.MulticlassLabels(f_labels_train)
labels_test = modshogun.MulticlassLabels(f_labels_test)
RealFeatures features_train = new RealFeatures(f_feats_train);
RealFeatures features_test = new RealFeatures(f_feats_test);
MulticlassLabels labels_train = new MulticlassLabels(f_labels_train);
MulticlassLabels labels_test = new MulticlassLabels(f_labels_test);
auto features_train = some<CDenseFeatures<float64_t>>(f_feats_train);
auto features_test = some<CDenseFeatures<float64_t>>(f_feats_test);
auto labels_train = some<CMulticlassLabels>(f_labels_train);
auto labels_test = some<CMulticlassLabels>(f_labels_test);

In order to run CMulticlassLibSVM, we need to initialize a kernel like CGaussianKernel with training features and some parameters like \(C\) and epsilon i.e. residual convergence parameter which is optional.

C = 1.0
epsilon = 0.0001
gauss_kernel = GaussianKernel(features_train, features_train, 15)
C = 1.0;
epsilon = 0.0001;
gauss_kernel = GaussianKernel(features_train, features_train, 15);
double C = 1.0;
double epsilon = 0.0001;
GaussianKernel gauss_kernel = new GaussianKernel(features_train, features_train, 15);
C = 1.0
epsilon = 0.0001
gauss_kernel = Modshogun::GaussianKernel.new features_train, features_train, 15
C <- 1.0
epsilon <- 0.0001
gauss_kernel <- GaussianKernel(features_train, features_train, 15)
C = 1.0
epsilon = 0.0001
gauss_kernel = modshogun.GaussianKernel(features_train, features_train, 15)
double C = 1.0;
double epsilon = 0.0001;
GaussianKernel gauss_kernel = new GaussianKernel(features_train, features_train, 15);
auto C = 1.0;
auto epsilon = 0.0001;
auto gauss_kernel = some<CGaussianKernel>(features_train, features_train, 15);

We create an instance of the CMulticlassLibSVM classifier by passing it regularization coefficient, kernel and labels.

svm = MulticlassLibSVM(C, gauss_kernel, labels_train)
svm.set_epsilon(epsilon)
svm = MulticlassLibSVM(C, gauss_kernel, labels_train);
svm.set_epsilon(epsilon);
MulticlassLibSVM svm = new MulticlassLibSVM(C, gauss_kernel, labels_train);
svm.set_epsilon(epsilon);
svm = Modshogun::MulticlassLibSVM.new C, gauss_kernel, labels_train
svm.set_epsilon epsilon
svm <- MulticlassLibSVM(C, gauss_kernel, labels_train)
svm$set_epsilon(epsilon)
svm = modshogun.MulticlassLibSVM(C, gauss_kernel, labels_train)
svm:set_epsilon(epsilon)
MulticlassLibSVM svm = new MulticlassLibSVM(C, gauss_kernel, labels_train);
svm.set_epsilon(epsilon);
auto svm = some<CMulticlassLibSVM>(C, gauss_kernel, labels_train);
svm->set_epsilon(epsilon);

Then we train and apply it to test data, which here gives CMulticlassLabels.

svm.train()
labels_predict = svm.apply_multiclass(features_test)
svm.train();
labels_predict = svm.apply_multiclass(features_test);
svm.train();
MulticlassLabels labels_predict = svm.apply_multiclass(features_test);
svm.train 
labels_predict = svm.apply_multiclass features_test
svm$train()
labels_predict <- svm$apply_multiclass(features_test)
svm:train()
labels_predict = svm:apply_multiclass(features_test)
svm.train();
MulticlassLabels labels_predict = svm.apply_multiclass(features_test);
svm->train();
auto labels_predict = svm->apply_multiclass(features_test);

Finally, we can evaluate test performance via e.g. CMulticlassAccuracy.