Install LibSVM in Matlab, GNU Octave and Python

Matlab and Octave are popular for machine learning prototypes due to their easier to learn (vs. R) interface. Python via scikit-learn is also a top choice for machine learning. Here’s how to install LibSVM for Matlab and GNU Octave.

0. Prereqs

apt install make git g++

1. Compile LibSVM

git clone https://github.com/cjlin1/libsvm

cd libsvm 

make

That creates executables svm-train svm-predict svm-scale. Now we compile the Matlab/Octave and Python modules, for which the API is similar.

2a. Compile LibSVM Matlab/Octave module

cd libsvm/matlab

Open Matlab or Octave, and from that internal Terminal, type (this uses make.m)

make

which creates a few .mex files. See the matlab/README for examples of using LibSVM from Matlab and Octave.

2b. Compile LibSVM Python module

cd libsvm/python

make

See the python/README for examples of using LibSVM from Python.