-
Notifications
You must be signed in to change notification settings - Fork 0
/
boost_DT_Dota_TrainNTest.py
75 lines (54 loc) · 2.23 KB
/
boost_DT_Dota_TrainNTest.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
64
65
66
67
68
69
70
71
72
73
74
75
import config
import data_handler
import logging
import datetime
from sklearn.ensemble import AdaBoostClassifier
start_time = datetime.datetime.now()
FORMAT = '%(asctime)-12s[%(levelname)s] %(message)s'
logging.basicConfig(level=logging.INFO, format=FORMAT, datefmt='%Y-%m-%d %H:%M:%S')
logging.info('start program-----------------')
# info for data
dota_size = 92650
dota_step = 92650/10
#True will run on various training sets, false will do once
multipleTests = True
learn = 0.01
approach = "./boost_DT/boost_DT_"
dota_time = 0
dota_data = []
test_data_prediction = []
boost = AdaBoostClassifier()
headers = "estimators,Time (s),Percent Correct, Percent +, Percent -, Percent + correct, Percent - correct, False + percent, False - percent\n"
if multipleTests:
file = open(approach + config.dota_analysis, 'w')
file.write(str(learn) + "\n")
file.write(headers)
for i in range(10): # for testing
trialTime = datetime.datetime.now()
boost = AdaBoostClassifier(n_estimators = (1 + i) * 10, learning_rate = learn)
line = "%d," % ((i + 1) * 10)
logging.info('Getting Data............')
dota_data = data_handler.getDotaData(1, dota_size)
logging.info('Fitting Data............')
boost.fit(dota_data[0], dota_data[1])
logging.info('Testing Data............')
test_data_prediction = boost.predict(dota_data[2])
res = data_handler.recordResults(1, -1, config.dota_results,dota_data[3], test_data_prediction, approach, False)
trialTime = (datetime.datetime.now() - trialTime).seconds
line += "%.2f," %trialTime
for item in res:
line += "%.5f%%," % item
line = line[:-1] + "\n"
file.write(line)
logging.info("FINISHED TEST #%d/10 time: %d" % ((i + 1), trialTime))
file.close()
else:
dota_data = data_handler.getDotaData(1, dota_size)
boost.fit(dota_data[0], dota_data[1])
test_data_prediction = boost.predict(dota_data[2])
data_handler.recordResults(1, -1, config.dota_results,dota_data[3], test_data_prediction, approach, True)
end_time = datetime.datetime.now()
dota_time = (end_time - start_time).seconds
#End dota
logging.info('total dota running time: %.2f seconds' % dota_time)
logging.info('end program-----------------')