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

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. ...

The best content for your career. Discover unlimited learning
on demand for around $1/day.