Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
28 lines (24 sloc) 698 Bytes
require 'csv'
require 'nbayes'
csv_file = ARGV[0]
if csv_file.nil?
raise "Run as: ruby train.rb foo.csv"
end
begin
nbayes.from("results.yml")
nbayes.reset_after_import()
rescue
nbayes = NBayes::Base.new
end
csv_data = CSV.read csv_file
p headers = csv_data.shift.map {|i| i.to_s }
string_data = csv_data.map {|row| row.map {|cell| cell.to_s } }
projects_array = string_data.map {|row| Hash[*headers.zip(row).flatten].inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo} }
projects_array.each {|x|
if x[:funded_on].length > 1
nbayes.train( x[:about_project].split(/\s+/), 'awesome' )
else
nbayes.train( x[:about_project].split(/\s+/), 'ok' )
end
}
nbayes.dump("results.yml")