Sha256: f39b1ca23b2d9617bc95f7240b6683bae75950c84a691fab662686f200e11374

Contents?: true

Size: 932 Bytes

Versions: 1

Compression:

Stored size: 932 Bytes

Contents

#!/usr/bin/ruby1.8
require 'rubygems'
require 'SVM'
include SVM
puts "TEST of the Ruby libsvm bindings"
puts "------------------------------------"
pa = Parameter.new
pa.C = 100
pa.svm_type = NU_SVC
pa.degree = 1
pa.coef0 = 0
pa.eps= 0.001
s = Marshal.dump(pa)
lpa = Marshal.load(s)
sp = Problem.new
labels = [0, 1, 1, 0]
samples = [[0,0], [0,1], [1,0], [1,1]]
labels.each_index { |i| sp.addExample(labels[i], samples[i]) }
kernels = [ LINEAR, POLY, RBF, SIGMOID ]
knames = [ 'LINEAR ', 'POLY   ', 'RBF    ', 'SIGMOID' ]
kernels.each_index { |j|
  pa.kernel_type = kernels[j]
  m = Model.new(sp, pa)
  ec = 0
  labels.each_index { |i|
    pred, probs = m.predict_probability(samples[i])
    puts "Got #{pred} and #{probs.join(',')} for sample: [#{samples[i].join(',')}]  Label: #{labels[i]}  Pred: #{pred} Kernel: #{knames[j]} sv: #{m.svcount}"
    ec += 1 if labels[i] != pred
  }
  puts "Kernel #{knames[j]} made #{ec} errors"
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gohanlonllc-libsvm-ruby-2.8.4 test/test.rb