Created
December 11, 2011 11:18
-
-
Save neovintage/1460023 to your computer and use it in GitHub Desktop.
Libsvm Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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