Skip to content

Instantly share code, notes, and snippets.

@neovintage
Created December 11, 2011 11:18
Show Gist options
  • Save neovintage/1460023 to your computer and use it in GitHub Desktop.
Save neovintage/1460023 to your computer and use it in GitHub Desktop.
Libsvm Example
require 'libsvm'
# This library is namespaced.
problem = Libsvm::Problem.new
parameter = Libsvm::SvmParameter.new
parameter.cache_size = 1 # in megabytes
parameter.eps = 0.001
parameter.c = 10
examples = [ [1,0,1], [-1,0,-1] ].map {|ary| Libsvm::Node.features(ary) }
labels = [1, -1]
problem.set_examples(labels, examples)
model = Libsvm::Model.train(problem, parameter)
pred = model.predict(Node.features(1, 1, 1))
puts "Example [1, 1, 1] - Predicted #{pred}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment