lib/twss/trainer.rb in twss-0.0.4 vs lib/twss/trainer.rb in twss-0.0.5

- old
+ new

@@ -2,16 +2,15 @@ module TWSS class Trainer - attr_reader :engine, :training_percentage + attr_reader :engine def initialize(engine, options = {}) @engine = engine engine.clear_state! - @training_percentage = options[:training_percentage] || 0.9 end def train path = File.join(File.dirname(__FILE__), '../../data/') @@ -64,20 +63,20 @@ false_negatives = 0 false_positives = 0 total = 0 correct = 0 - test_each(positive_test_file, (total_positive * training_percentage).to_i) do |line, result| + test_each(positive_test_file) do |line, result| if result correct += 1 else false_negatives += 1 end total += 1 end - test_each(negative_test_file, (total_negative * training_percentage).to_i) do |line, result| + test_each(negative_test_file) do |line, result| if !result correct += 1 else false_positives += 1 end @@ -90,13 +89,12 @@ puts "False positives: #{false_positives} (#{100 * false_positives / total_negative.to_f}%)" puts "False negatives: #{false_negatives} (#{100 * false_negatives / total_positive.to_f}%)" puts end - def test_each(file, sample_size, &blk) + def test_each(file, &blk) i = 0 File.read(file).each_line do |line| - return if i > sample_size l = line.strip unless l.empty? r = TWSS(l) puts l + ' => ' + r.to_s blk.call(l, r) \ No newline at end of file