2 \page static_tutorial Tutorial for Static Interfaces
4 SHOGUN provides "static" interfaces to Matlab(tm), R, Python, Octave and
5 provides a command line stand-a-lone executable. The idea behind the static
6 interfaces is to provide a simple environment just enough to do simple
7 experiments. For example, it will allow you to train and evaluate a classifier
8 but not go beyond that. In case you are looking for basically unlimited
9 extensibility (multiple methods like classifiers potentially sharing data and
10 interacting) you might want to look at the \subpage modular_tutorial "Modular
13 In this tutorial we demonstrate how to use shogun to create a simple
14 gaussian kernel based support vector machine classifier but first
15 things first. Lets start up R, python, octave or matlab load the shogun
18 \section start_shogun_static Starting SHOGUN
19 To start SHOGUN in python, start python and type
25 For R issue (from within R)
31 For octave and matlab just make sure sg is in the path (use addpath). For the
32 cmdline interface just start the shogun executable
46 in the cmdline interface will show the help screen. If not consult
47 \subpage installation on how to install shogun.
49 \section svm_tutorial_static Creating an SVM classifier
51 The rest of this tutorial assumes that the cmdline shogun executable
52 is used (but hints on how things work using other interfaces). The
55 <command> <option1> <option2> ...
57 here options are separated by spaces. For example
60 set_kernel GAUSSIAN REAL 10 1.2
63 will create a gaussian kernel that operates on real-valued features uses a
64 kernel cache of size 10 MB and kernel width of 1.2. In analogy the other the
65 cmdline for the other interfaces (python,r,...) would look like
68 sg('set_kernel', 'GAUSSIAN', 'REAL', 10, 1.2)
71 Note that there is little difference to the other interfaces, basically only
72 strings are marked as such and arguments comma separated.
74 We now use two random gaussians as inputs as train data:
76 set_features TRAIN ../data/fm_train_real.dat
79 (For other interfaces sth. like
81 sg('set_features', 'TRAIN', [ randn(2, 100)-1, randn(2,100)+1 ])
85 For training a supervised method like an SVM we need a labeling of the training
86 data, which we set via
88 set_labels TRAIN ../data/label_train_twoclass.dat
91 (For other interfaces, e.g. matlab/octave sth. like
93 sg('set_labels', 'TRAIN', sign(randn(1, 100)))
97 Now we create an SVM and set the SVM-C parameter to some hopefully sane value
98 (which in real applications needs tuning; like the kernel parameters (here
101 new_classifier LIBSVM
105 We then train our SVM:
110 We can now apply our classifier to unseen test data by loading some
111 test data and classifying the examples:
114 set_features TEST ../data/fm_test_real.dat
118 In case we want to save the classifiers, such that we don't have to perform
119 potentially time consuming training again we can save and load like this
122 save_classifier libsvm.model
124 load_classifier libsvm.model LIBSVM
127 Other interfaces (python,r...) could use the load/save functions but typically
128 one manually obtains and restores the model parameters, like
131 [b,alphas]=sg('get_classifier')
133 sg('set_classifier', b, alphas)
138 Finally, the complete example looks like this
139 \verbinclude classifier_libsvm.sg
141 and can be found together with many other \subpage examples "examples"
142 in examples/cmdline/classifier_libsvm.sg .
144 For users of other interfaces we show the translated example for completeness:
146 \li Static R Interface \verbinclude classifier_libsvm.R
147 \li Static Matlab/Octave Interface \verbinclude classifier_libsvm.m
148 \li Static Python Interface \verbinclude classifier_libsvm.py