-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
106 lines (92 loc) · 4.41 KB
/
build.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import copy
import os
import subprocess
MAP_METRIC = {
'acc': 'Accuracy',
'recall': 'Recall',
'f1_weighted': 'F1-Score (weighted)',
'precision': 'Precision',
'balanced_acc': 'Accuracy (balanced)',
'mcc': 'Matthew Correlation Coefficient',
'hamming_loss': "Hamming Loss",
'jaccard_similarity_score': "Jaccard Similarity Score",
'zero_one_loss': 'Zero-One Loss'
}
def main():
'''
for file in [f for f in os.listdir('appendix/tables') if f.endswith('.tex')]:
name = file.split('.', 1)[0]
print(name)
subprocess.call([
'pdflatex', '\\documentclass[varwidth]{standalone}[2011/12/21]\\pagestyle{empty}\\begin{document}\\begin{table}\\tiny \\input{appendix/tables/'+ name +'}\\end{table}\\end{document}'
])
subprocess.call(['convert', '-density', '300', '-trim', 'standalone.pdf', '-quality', '100', 'appendix/tables/{}.png'.format(name)])
'''
with open('multiclass.md', 'w') as file:
content = "# Multiclass\n\n"
content += "## Tables\n\n"
tables = [f for f in os.listdir('appendix/tables') if f.endswith('.png') and f.startswith('multiclass')]
for t in tables:
name = t.split('.', 1)[0]
metric = name.split('_', 1)[1]
content += '![{}]({})\n\n'.format(MAP_METRIC[metric],'appendix/tables/{}'.format(t))
content = "## Confusion Matrix\n\n"
tables = [f for f in os.listdir('appendix/cm') if f.endswith('.png') and f.startswith('multiclass')]
order = {}
for t in tables:
name = t.split('.', 1)[0]
rest = name.split('_', 3)[-1]
if rest.endswith('bag-of-words_only'):
method = rest[::-1].split('_', 2)[-1][::-1]
flavor = 'bag-of-words_only'
i = 0
elif rest.endswith('descriptive_features_only'):
method = rest[::-1].split('_', 3)[-1][::-1]
flavor = 'descriptive_features_only'
i = 1
else:
method = rest[::-1].split('_', 4)[-1][::-1]
flavor = 'descriptive_features_and_bag-of-words'
i = 2
if method not in order:
order[method] = ['', '', '']
order[method][i] = flavor
for method, flavors in order.iteritems():
for flavor in flavors:
content += '![{} - {}]({})\n\n'.format(method.replace('_', ' ').title(), flavor.replace('_', ' ').title(),
'appendix/cm/multiclass_cm_test_{}_{}.png'.format(method, flavor))
file.write(content)
with open('multilabel.md', 'w') as file:
content = "# Multilabel\n\n"
content += "## Tables\n\n"
tables = [f for f in os.listdir('appendix/tables') if f.endswith('.png') and f.startswith('multilabel')]
for t in tables:
name = t.split('.', 1)[0]
metric = name.split('_', 1)[1]
content += '![{}]({})\n\n'.format(MAP_METRIC[metric],'appendix/tables/{}'.format(t))
file.write(content)
with open('binary.md', 'w') as file:
content = "# Binary\n\n"
content += "## Tables\n\n"
tables = [f for f in os.listdir('appendix/tables') if f.endswith('.png') and f.startswith('binary')]
for t in tables:
name = t.split('.', 1)[0]
if 'summary' in name:
metric = name.split('_', 1)[1][::-1].split('_', 1)[-1][::-1]
content += '![Summary {}]({})\n\n'.format(MAP_METRIC[metric],'appendix/tables/{}'.format(t))
elif 'best' in name:
metric = name.split('_', 1)[1][::-1].split('_', 1)[-1][::-1]
content += '![Best {}]({})\n\n'.format(MAP_METRIC[metric],'appendix/tables/{}'.format(t))
else:
metric = name.split('_', 1)[1][::-1].split('_', 2)[-1][::-1]
article = name.split('_', 1)[1][::-1].split('_', 1)[:-1][-1]
content += '![Article {} {}]({})\n\n'.format(article, MAP_METRIC[metric],'appendix/tables/{}'.format(t))
content += "## Learning Curves\n\n"
tables = [f for f in os.listdir('appendix/lc') if f.endswith('.png')]
for t in tables:
name = t.split('.', 1)[0]
article = name[3:].replace('_', ' ').title()
content += '![{}]({})\n\n'.format(article,'appendix/lc/{}'.format(t))
file.write(content)
if __name__ == "__main__":
main()