Created
August 1, 2013 00:59
-
-
Save gummibeatz/6127638 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Change if a[1] == 1 to
if a[1].to_i == 1
and the same for the rest of the if statements