diff options
author | Patrick Simianer <p@simianer.de> | 2016-04-08 23:19:28 +0200 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2016-04-08 23:19:28 +0200 |
commit | 34d621606e58adeb35aa33f8503e105189a7c0d5 (patch) | |
tree | 18931029e5ceed1e2c2d77bfdf2b87a216633366 /test_n_learn.rb | |
parent | 81f6b20d1c41d8906900c57ab71ec08a007ea02c (diff) |
Diffstat (limited to 'test_n_learn.rb')
-rwxr-xr-x | test_n_learn.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test_n_learn.rb b/test_n_learn.rb new file mode 100755 index 0000000..03c0cd4 --- /dev/null +++ b/test_n_learn.rb @@ -0,0 +1,32 @@ +#!/usr/bin/env ruby + +require 'zipf' + +STDERR.write "reading test data...\n" +test = [] +test_f = ReadFile.new ARGV[0] +threshold = ARGV[2].to_f +signals = ReadFile.new(ARGV[1]).readlines_strip.map{|i| (i.to_f)>=threshold} +n = 0 +while i = test_f.gets + test << SparseVector.from_kv(i.strip, '=', ' ') + n += 1 + STDERR.write "#{n}\n" if n%1000==0 +end +STDERR.write " test set size = #{test.size}\n" + +errors = 0 +w = SparseVector.from_kv ReadFile.new(ARGV[1]).read, "\t", "\n" + +test.each { |x| + m = w.dot(x) + if m <= 0.0 + errors += 1 + puts -1 + else + puts 1 + end +} + +STDERR.write "accuracy = #{(test.size-errors)/test.size.to_f}\n" + |