Skip to content
ThunderSVM - high-performance parallel SVMs - for Ruby
Ruby Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
test
.gitignore
.travis.yml
CHANGELOG.md
Gemfile
LICENSE.txt
NOTICE.txt
README.md
Rakefile
thundersvm.gemspec

README.md

ThunderSVM

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.

Build Status

Installation

First, install ThunderSVM. Add this line to your application’s Gemfile:

gem 'thundersvm'

Getting Started

Prep your data

x = [[1, 2], [3, 4], [5, 6], [7, 8]]
y = [1, 2, 3, 4]

Train a model

model = ThunderSVM::Regressor.new
model.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_vectors

Cross-Validation

Perform cross-validation

model.cv(x, y)

Specify the number of folds

model.cv(x, y, folds: 5)

Parameters

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 function
  gamma: nil,          # gamma in kernel function
  coef0: 0,            # coef0 in kernel function
  c: 1,                # parameter C of C-SVC, epsilon-SVR, and nu-SVR
  nu: 0.5,             # parameter nu of nu-SVC, one-class SVM, and nu-SVR
  epsilon: 0.1,        # epsilon in loss function of epsilon-SVR
  max_memory: 8192,    # constrain the maximum memory size (MB) that thundersvm uses
  tolerance: 0.001,    # tolerance of termination criterion
  probability: false,  # whether to train a SVC or SVR model for probability estimates
  gpu: 0,              # specify which gpu to use
  cores: nil,          # number of cpu cores to use (defaults to all)
  verbose: false       # verbose mode
)

Data

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")

ThunderSVM Installation

Linux

git clone --recursive --branch 0.3.3 https://github.com/Xtra-Computing/thundersvm
cd thundersvm
mkdir build
cd build
cmake -DUSE_CUDA=OFF -DUSE_EIGEN=ON ..
make

For CUDA, remove the cmake flags.

Specify the path to the shared library with:

ThunderSVM.ffi_lib << "path/to/build/lib/libthundersvm.so"

Mac

Install dependencies:

brew install cmake gcc

And run:

git clone --recursive --branch 0.3.3 https://github.com/Xtra-Computing/thundersvm
cd thundersvm
mkdir build
cd build
cmake -DUSE_CUDA=OFF -DUSE_EIGEN=ON -DCMAKE_C_COMPILER=gcc-9 -DCMAKE_CXX_COMPILER=g++-9 ..
make

Specify the path to the shared library with:

ThunderSVM.ffi_lib << "path/to/build/lib/libthundersvm.dylib"

Windows

Follow the official instructions.

Resources

History

View the changelog

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

To get started with development:

git clone https://github.com/ankane/thundersvm.git
cd thundersvm
bundle install
bundle exec rake test
You can’t perform that action at this time.