-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocess.rb
57 lines (34 loc) · 1.26 KB
/
preprocess.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
module Processor
def Processor.processIt!
trainingData = Hash.new
inputs = gets.chomp
inputs.split.each do |className|
trainingData[className] = []
end
#trainingData = {"1" => [], "2" => [] }
File.foreach('train/train2.csv') do |line| #Make changes here to add your own file. Replace train.csv
inputDataRow = line.split(',')
className = inputDataRow.pop.chomp
inputDataRow.map {|i| i.to_f}
trainingData[className].push(inputDataRow)
end
counter = 0
total = 0
nbc = Classifier.new(trainingData)
File.foreach('test/test2.csv') do |line| #Make changes here to add your own file. Replace test.csv
dataToClassify = line.split(',')
correctClassName = dataToClassify.pop.chomp
dataToClassify = dataToClassify.map(&:to_f)
# features.map {|feature| feature.to_f}
className = nbc.classifyIt!(dataToClassify)
if className == correctClassName
counter += 1
total += 1
else total += 1
end
end
total = total.to_f
accuracy = (counter/total)*100.0
puts "Accuracy of RuBayes Multiclass Classifier is: " + accuracy.to_s + "%"
end
end