/
MyProgram.py
61 lines (50 loc) · 1.38 KB
/
MyProgram.py
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
58
59
##########################################
#
# MyProgram.py
# Juan Andres Carpio
# Naomi Serfaty
#
##########################################
import sys
import NaiveBayes
import KNN
import Helper
import CrossValidation
##############################
# #
# Main program #
# #
##############################
#Read information from the command line
file = sys.argv[1]
examples = sys.argv[2]
algorithm = sys.argv[3]
#Check with algorithm will be used
if algorithm != 'NB':
algorithm = algorithm.replace("NN", "")
#Read data and train it for Naive Bayes
data = Helper.readfile(file)
train = NaiveBayes.train_nb(data)
#Read example data
f = open(examples, 'r')
#Test every example
for line in f:
array_line = line.split(',')
row = []
length = len(array_line)
for i in range (0,length):
row.append(float(array_line[i]))
#Apply the algorithm
if algorithm != 'NB':
print KNN.knearest(int(algorithm),data,row)
else:
print NaiveBayes.naive_bayes(row,train)
##############################
# #
# Cross validation called #
# when need it #
# #
##############################
#folds = CrossValidation.fold_divide(data)
#print CrossValidation.cross_validation_nn(1,folds)
#print CrossValidation.cross_validation_nb(folds)