Skip to content

Instantly share code, notes, and snippets.

@gummibeatz
Created August 1, 2013 00:59
Show Gist options
  • Save gummibeatz/6127638 to your computer and use it in GitHub Desktop.
Save gummibeatz/6127638 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")
puts a[1]
if a[1] == 0
puts "yes"
cls.train(:no,a[0])
end
if a[1] == 1
cls.train(:yes, a[0])
end
if a[1]== 2
cls.train(:maybe, a[0])
end
end
tester = File.readlines('comp.txt')
File.open('alcohol_classify.txt') do |s|
file.each do |line|
b = line.split(' ')
s.puts cls.classify(b)
end
end
@mac389
Copy link

mac389 commented Aug 1, 2013

Change if a[1] == 1 to

if a[1].to_i == 1

and the same for the rest of the if statements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment