Skip to content

Instantly share code, notes, and snippets.

@hannic
Created December 2, 2012 19:58
Show Gist options
  • Save hannic/4190737 to your computer and use it in GitHub Desktop.
Save hannic/4190737 to your computer and use it in GitHub Desktop.
txt to kernel (libsvm)
#!/usr/bin/ruby
#
if ARGV.length==0 then
puts "Usage #{$0} inputmatrix classlabels gamma"
exit
end
gamma=2**ARGV[2].to_f
File.open(ARGV[0]) do |matrix|
File.open(ARGV[1]) do |labels|
eof=false
while !eof do
row=matrix.gets
label=labels.gets
eof=true if !row or !label
if !eof then
elems=row.split
print label
elems.length.times { |i| print " #{i+1}:#{Math.exp(-gamma*elems[i].to_f)}" }
puts
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment