Skip to content

karpathy/EigenLibSVM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EigenLibSVM

Andrej Karpathy 1 May 2012

This is a small C++ wrapper to call libsvm if you use the Eigen matrix library. Dependencies consist of libsvm and eigen3 library. Current support is only for dense matrices with linear kernel svm.

Usage

vector<int> yhat;
SVMClassifier svm;
svm.train(X, y);
svm.test(X, yhat);

where X is an Eigen::MatrixXf NxD matrix, y is an Eigen::MatrixXf Nx1 matrix of labels (-1 or 1), or a vector<int> of labels. You can also save and load the models:

svm.saveModel("tmp_model");  
svm.loadModel("tmp_model");  

there is now also functionality to directly get the weights:

Eigen::MatrixXf w;
float b;
svm.getw(w, b);
Eigen::MatrixXf margin= ((X * w).array() + b).matrix(); // yhat = sign(margin)

See demo for details.

Install

$ sudo apt-get install libsvm-dev  
$ sudo apt-get install libeigen3-dev  
$ git clone git@github.com:karpathy/EigenLibSVM.git  
$ cd EigenLibSVM  
$ mkdir build  
$ cd build  
$ cmake ..  
$ make  
$ ./svm_test  

where the last line will run a tiny demo that makes sure everything installed ok (it runs almost instantly)

License

BSD

About

A wrapper for LibSVM that lets you train SVM's directly on Eigen library matrices in C++

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published