-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_logs_metrics.py
executable file
·59 lines (47 loc) · 2.33 KB
/
get_logs_metrics.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
import json
import re
from typing import Tuple, Optional
def get_n_features_and_metric(line: str) -> Tuple[Optional[int], Optional[float]]:
"""
Retrieves the number of features and the metric obtained
:param line: Current line to parse
:return: Tuple with both numbers. None in both data if it's not a valid line
"""
important_str = 'Fitness: '
if important_str not in line:
return None, None
splitted = line.split(important_str)
# Gets metric
metric = float(splitted[1])
# Gets number of features
suffix = ' features.'
new_result = re.findall(r'\d+' + suffix, splitted[0])
n_features = new_result[0].rstrip(suffix)
return int(n_features), metric
def get_all_n_features_and_metrics(file_path: str):
json_result = {
'n_features': [],
'fitness': []
}
with open(file_path, 'r') as f:
for line in f.readlines():
n_features, fitness_value = get_n_features_and_metric(line)
if n_features is None or fitness_value is None:
continue
json_result['n_features'].append(n_features)
json_result['fitness'].append(fitness_value)
with open(f'{file_path}_result.json', 'w+') as outfile:
json.dump(json_result, outfile)
def main():
get_all_n_features_and_metrics('./Logs/logs_times_optimizer_rbtree_kernel_cosine_30_it.txt')
get_all_n_features_and_metrics('./Logs/logs_times_optimizer_rbtree_kernel_sigmoid_30_it.txt')
get_all_n_features_and_metrics('./Logs/logs_times_optimizer_rbtree_kernel_rbf_30_it.txt')
get_all_n_features_and_metrics('./Logs/logs_times_optimizer_rbtree_kernel_poly_30_it.txt')
get_all_n_features_and_metrics('./Logs/logs_times_optimizer_rbtree_kernel_linear_30_it.txt')
get_all_n_features_and_metrics('./Logs/logs_times_optimizer_avltree_kernel_cosine_30_it_with_training.txt')
get_all_n_features_and_metrics('./Logs/logs_times_optimizer_avltree_kernel_sigmoid_30_it_with_training.txt')
get_all_n_features_and_metrics('./Logs/logs_times_optimizer_avltree_kernel_rbf_30_it_with_training.txt')
get_all_n_features_and_metrics('./Logs/logs_times_optimizer_avltree_kernel_poly_30_it_with_training.txt')
get_all_n_features_and_metrics('./Logs/logs_times_optimizer_avltree_kernel_linear_30_it_with_training.txt')
if __name__ == '__main__':
main()