Created
December 2, 2012 19:58
-
-
Save hannic/4190737 to your computer and use it in GitHub Desktop.
txt to kernel (libsvm)
This file contains hidden or 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
#!/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