libsvm-go: Support Vector Machine
This is a full port of LIBSVM in the Go programming language. LIBSVM is a suite of tools and an API library for support vector classification, regression, and distribution estimation. This port implements the libsvm library in the form of a Go package called libSvm
. It also implements the svm-train
and svm-predict
command line tools.
This port has no external package dependencies, and uses only the native standard library.
Installation
go get github.com/ewalker544/libsvm-go
make
Compatibility Notes
I have tried to make the Go implementation of svm-train
and svm-predict
plug-in compatibile with the original LIBSVM 3.18 distribution. This is to allow you to use the other tools available in the original distribution, like easy.py
and grid.py
.
svm-predict
should be 100% plug-in compatibile. However, svm-train
is plug-in compatible with one exception. The exception is the parameter weight flag used in the command. In this implementation, the flag is
-w i,weight : set the parameter C of class i to weight*C, for C-SVC (default 1)
For full documentation of the svm-train
and svm-predict
commands, please refer to the original LIBSVM web site.
API Example
Training
import "github.com/ewalker544/libsvm-go"
param := libSvm.NewParameter()
param.KernelType = libSvm.POLY
model := libSvm.NewModel(param)
problem, err := libSvm.NewProblem("a9a.train", param)
model.Train(problem)
model.Dump("a9a.model")
Predicting
import "github.com/ewalker544/libsvm-go"
model := libSvm.NewModelFromFile("a9a.model")
x := make(map[int]float64)
predictLabel := model.Predict(x)