Skip to content

Instantly share code, notes, and snippets.

@gummibeatz
Created August 1, 2013 01:49
Show Gist options
  • Save gummibeatz/6127813 to your computer and use it in GitHub Desktop.
Save gummibeatz/6127813 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'naive_bayes'
cls = NaiveBayes.new(:yes,:no,:maybe)
#put in words to ignore inside single quotes separated by commas
file=File.readlines('test.txt')
#classifies tweets from each row
file.each do |line|
a = line.split("\t")
d = a[0].split(' ')
counter=0
d.each do
puts d[counter]
if a[1].to_i == 0
cls.train(:no,d[counter])
end
if a[1].to_i == 1
cls.train(:yes,d[counter])
end
if a[1].to_i == 2
cls.train(:maybe,d[counter])
end
counter=counter+1
end
end
line = "Good chicken is good"
b = line.split(' ')
print cls.classify(b)
tester = File.readlines('comp.txt')
File.open('alcohol_classify.txt') do |s|
file.each do |line|
b = line.split(' ')
s.print cls.classify(b)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment