Navigation: [tom's page] [Joachim's SVMlight Home]

MATLAB/MEX Interface to SVMlight

[download] - download links and instructions

Updated July 6, 2005

MEX-SVM is an interface between MATLAB and SVMlight , a powerful and efficient SVM package developed by Thorsten Joachims. The primary goal of this package is to have a simple and efficient interface between the two packages.

Why Another MEX-SVM Package?

How to Use the Package?

The interface is extremely simple. There are detailed installation and usage instructions in the distributions. The following is a summary of the capabilities of this package.

There are two MATLAB functions, svmlearn and svmclassify. The first function, svmlearn, takes three arguments. The first two arguments, x and y,are matrices corresponding to the training data (x) and labels (y). The third parameter is a string composed of the parameters of the command-line version of the SVMlight software. The output of svmlearn is a MATLAB structure derived from the fields of the SVMlight model. See [model] for a description of each parameter and its corresponding SVMlight source parameter

The second MATLAB function, svmclassify, also requires three input parameters. The first two are the x and y parameters of data to be classified. The third parameter is the model structure from a previous call to svmlearn. Two outputs are produced, the error rate and an array of predictions.

Following is a sample session demonstrating the use of the package. In the following example, assume that X is a 400x2 MATLAB matrix corresponding to the training data, and Y is a 400x1 MATLAB matrix corresponding to the class labels. The given parameter list sets SVMlight to use the RBF kernel (-t 2), set gamma to 0.3 (-g 0.3), and set C to be 0.5 (-c 0.5). Any of the standard SVMlight command line arguments may be specified, see SVMlight documentation for details. (note: one useful parameter is '-v 0' to turn SVMlight output off completely.)


>> model = svmlearn(x,y,'-t 2 -g 0.3 -c 0.5')
Optimizing...................................................................
.............................................................................
.............................................................................
.............................................................................
.....
 Checking optimality of inactive variables...done.
 Number of inactive variables = 335
done. (304 iterations)
Optimization finished (46 misclassified, maxdiff=0.00073).
Runtime in cpu-seconds: 0.13
Number of SV: 272 (including 262 at upper bound)
Computing XiAlpha-estimates...done
Runtime for XiAlpha-estimates in cpu-seconds: 0.00
Number of kernel evaluations: 79422

model = 

           sv_num: 273
      upper_bound: 262
                b: -0.1069
         totwords: 2
           totdoc: 400
        loo_error: -1
       loo_recall: -1
    loo_precision: []
         xa_error: 60.2500
        xa_recall: 44.7005
     xa_precision: 44.4954
          maxdiff: 7.3188e-004
       r_delta_sq: 1.8625
      r_delta_avg: 0.8535
     model_length: 7.6915
             loss: 148.5834
            vcdim: 107.3005
            alpha: [400x1 double]
      lin_weights: []
            index: [400x1 double]
           supvec: [273x2 double]
      kernel_parm: [1x1 struct]


>> [err , predictions ] = svmclassify(x,y,model);
>> err

err =

    0.1150

>> 

If you find this package useful or find a bug in it, please send me an email.


© Tom Briggs,
All Rights Reserved.

This page last modified: Wednesday, July 06, 2005