fa.bianp.net

Low-level routines for Support Vector Machines

Category: General, Python, scikit-learn

I've been working lately in improving the low-level API of the libsvm bindings in scikit-learn. The goal is to provide an API that encourages an efficient use of these libraries for expert users. These are methods that have lower overhead than the object-oriented interface as they are closer to the C implementation, but do not have an interface as polished. Here, all parameters are expected to be of the correct type, and submitting one of the wrong type will make the function exit immediately with a ValueError. For instance, input data is expected to be of type float64, even for class labels! Another peculiarity of these methods is that they only take and return numpy arrays. No custom objects, all method take and return arrays. That looks something like: [cc lang="python"] import numpy as np from scikits.learn import svm, datasets iris = datasets.load_iris() iris.target = iris.target.astype(np.float64) learned_params = svm.libsvm.fit(iris.data, iris.target) pred = svm.libsvm.predict(iris.data, *learned_params) [/cc] Here, I used the fact that the parameters returned by libsvm.fit can just passed to libsvm.predict. However, any other given parameters should be manually passed to both method.