-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdaBoostPgm.py
64 lines (54 loc) · 1.36 KB
/
AdaBoostPgm.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
60
61
62
63
import cPickle
from sklearn.ensemble import AdaBoostClassifier
#df = pd.read_csv("../train_data.txt")
#print(df.head())
#print df.ix[0]
file = open("../train_data_new.txt",'r')
labelfile = open("../train_label_new.txt",'r')
label = []
for line in labelfile.readlines():
label.append(float(line))
alldata = file.readlines()
'''
inArr = []
for line in alldata:
line = line.split(',')
line = map(lambda x: float(x), line)
inArr.append(line)
'''
testfile = open("../test_data_new.txt",'r')
test = []
for line in testfile.readlines():
line = line.split(',')
line = map(lambda x: float(x), line)
test.append(line)
'''
clf = AdaBoostClassifier(n_estimators=1800)
model = clf.fit(inArr, label)
with open('ct','wb') as f:
cPickle .dump(model, f)
'''
with open('ct','rb') as f:
model = cPickle.load(f)
preds = model.predict(test)
print preds
target = open('AdaBoostOut.txt', 'w')
lstout = []
lstout = str(preds).strip('[*]').split('.')
for line in lstout:
valStr = line.strip()
if(valStr != '\t' and valStr !=''):
target.write(valStr+'\n')
target.close()
'''
def calcerror(actual, predicted):
correct = 0
incorrect = 0
for i in range(len(actual)):
if actual[i] == predicted[i]:
correct = correct + 1
else:
incorrect = incorrect + 1
print correct, incorrect
calcerror(label, preds)
'''