forked from charliermarsh/online_boosting
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_num_learners.py
48 lines (42 loc) · 1.81 KB
/
main_num_learners.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
import argparse
from random import seed
from yaml import dump
from utils.experiment import testNumLearners
from utils.utils import *
if __name__ == "__main__":
seed(0)
parser = argparse.ArgumentParser(
description='Test error for a combination of ensembler and weak learner.')
parser.add_argument('dataset', help='dataset filename')
parser.add_argument('ensembler', help='chosen ensembler')
parser.add_argument('weak_learner', help='chosen weak learner')
parser.add_argument(
'start', help='initial number of weak learners', type=int)
parser.add_argument('end', help='final number of weak learners', type=int)
parser.add_argument(
'inc', help='increment for number of weak learners', type=int)
parser.add_argument('--record', action='store_const',
const=True, default=False, help='export the results in YAML format')
parser.add_argument(
'trials', help='number of trials (each with different shuffling of the data); defaults to 1', type=int, default=1, nargs='?')
args = parser.parse_args()
ensembler = get_ensembler(args.ensembler)
weak_learner = get_weak_learner(args.weak_learner)
data = load_data("data/" + args.dataset)
accuracy = testNumLearners(
ensembler, weak_learner, data, args.start, args.end, args.inc, trials=args.trials)
print accuracy
if args.record:
results = {
'accuracy': accuracy,
'booster': args.ensembler,
'weak_learner': args.weak_learner,
'trials': args.trials,
'seed': 0
}
filename = args.ensembler + "_" + \
args.weak_learner + "_" + \
str(args.start) + "_" + str(args.end) + \
"_" + str(args.inc) + ".yml"
f = open(filename, 'w+')
f.write(dump(results))