Cover by Toby Segaran

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

Using LIBSVM

The explanation in the previous section should help you understand how and why support-vector machines work, but the algorithm for training a support-vector machine involves mathematical concepts that are very computationally intensive and are beyond the scope of this chapter. For these reasons, this section will introduce an open-source library called LIBSVM, which can train an SVM model, make predictions, and test the predictions within a dataset. It even has built-in support for the radial-basis function and other kernel methods.

Getting LIBSVM

You can download LIBSVM from http://www.csie.ntu.edu.tw/˜cjlin/libsvm.

LIBSVM is written in C++ and includes a version written in Java. The download package includes a Python wrapper called svm.py. In order to use svm.py, you need compiled versions of LIBSVM for your platform. If you're using Windows, a DLL called svmc.dll is included. (Python 2.5 requires that you rename this file to svmc.pyd because it can't import libraries with DLL extensions.) The documentation for LIBSVM explains how to compile the library for other platforms.

A Sample Session

Once you have a compiled version of LIBSVM, put it and svm.py in your Python path or working directory. You can now import the library in your Python session and try a simple problem:

>>>from svm import *

The first step is to create a simple dataset. LIBSVM reads the data from a tuple containing two lists. The first list contains the classes and the second list contains the input data. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required