ThunderSVM - high performance parallel SVMs - for Ruby
🔥 Uses GPUs and multi-core CPUs for blazing performance
For a great intro on support vector machines, check out this video.
Add this line to your application’s Gemfile:
gem"thundersvm"On Mac, also install OpenMP:
brew install libompPrep your data
x=[[1,2],[3,4],[5,6],[7,8]]y=[1,2,3,4]Train a model
model=ThunderSVM::Regressor.newmodel.fit(x,y)Use ThunderSVM::Classifier for classification and ThunderSVM::Model for other models
Make predictions
model.predict(x)Save the model to a file
model.save_model("model.txt")Load the model from a file
model=ThunderSVM.load_model("model.txt")Get support vectors
model.support_vectorsPerform cross-validation
model.cv(x,y)Specify the number of folds
model.cv(x,y,folds: 5)Defaults shown below
ThunderSVM::Model.new(svm_type: :c_svc,# type of SVM (c_svc, nu_svc, one_class, epsilon_svr, nu_svr)kernel: :rbf,# type of kernel function (linear, polynomial, rbf, sigmoid)degree: 3,# degree in kernel functiongamma: nil,# gamma in kernel functioncoef0: 0,# coef0 in kernel functionc: 1,# parameter C of C-SVC, epsilon-SVR, and nu-SVRnu: 0.5,# parameter nu of nu-SVC, one-class SVM, and nu-SVRepsilon: 0.1,# epsilon in loss function of epsilon-SVRmax_memory: 8192,# constrain the maximum memory size (MB) that thundersvm usestolerance: 0.001,# tolerance of termination criterionprobability: false,# whether to train a SVC or SVR model for probability estimatesgpu: 0,# specify which gpu to usecores: nil,# number of cpu cores to use (defaults to all)verbose: false# verbose mode)Data can be a Ruby array
[[1,2],[3,4],[5,6],[7,8]]Or a Numo array
Numo::DFloat.cast([[1,2],[3,4],[5,6],[7,8]])Or the path a file in libsvm format (better for sparse data)
model.fit("train.txt")model.predict("test.txt")To run ThunderSVM on GPUs, you’ll need to build the library from source.
git clone --recursive --branch v0.3.4 https://github.com/Xtra-Computing/thundersvm
cd thundersvm
mkdir build
cd build
cmake ..
makeSpecify the path to the shared library with:
ThunderSVM.ffi_lib="path/to/build/lib/libthundersvm.so"Follow the official instructions. Specify the path to the shared library with:
ThunderSVM.ffi_lib="path/to/build/lib/libthundersvm.dll"View the changelog
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new features
To get started with development:
git clone https://github.com/ankane/thundersvm-ruby.git
cd thundersvm-ruby
bundle install
bundle exec rake test