-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain_with_csv.py
More file actions
87 lines (79 loc) · 5.13 KB
/
Copy pathtrain_with_csv.py
File metadata and controls
87 lines (79 loc) · 5.13 KB
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
import pandas as pd
import numpy as np
from models import models
from datetime import datetime
from datetime import timedelta
from utils import analysis_model, save_result
from train import h_block_analyzer
import json
if __name__ == '__main__':
args = pd.read_csv("datasets/args.csv")
for dataset in args.dataset:
log_dir = "logs/"
opt = args[args.dataset == dataset].iloc[0]
opt.features = eval(opt.features)
opt.segments_times = eval(opt.segments_times)
opt.segments_overlaps = eval(opt.segments_overlaps)
opt.decision_times = eval(opt.decision_times)
opt.decision_overlaps = eval(opt.decision_overlaps)
opt.model = eval(opt.model)
segments_times = opt.segments_times
segments_overlaps = opt.segments_overlaps
decision_times = opt.decision_times
decision_overlaps = opt.decision_overlaps
for model in opt.model[2:]:
for segments_time in segments_times:
for decision_time in decision_times:
for segments_overlap in segments_overlaps:
for decision_overlap in decision_overlaps:
classifier = getattr(models, model)(classes=opt.n_classes,
n_features=len(opt.features),
segments_size=segments_time * opt.sample_rate,
segments_overlap=segments_overlap,
decision_size=decision_time * opt.sample_rate,
decision_overlap=decision_overlap)
# cross-validation
start = datetime.now()
statistics = h_block_analyzer(db_path=opt.dataset,
sample_rate=opt.sample_rate,
features=opt.features,
n_classes=opt.n_classes,
noise_rate=opt.noise_rate,
segments_time=segments_time,
segments_overlap=segments_overlap,
classifier=classifier,
epochs=opt.epochs,
batch_size=opt.batch_size,
restore_best=opt.restore_best != 0,
data_length_time=opt.data_length_time,
n_h_block=opt.n_h_block,
n_train_h_block=opt.n_train_h_block,
n_valid_h_block=opt.n_valid_h_block,
n_test_h_block=opt.n_test_h_block,
h_moving_step=opt.h_moving_step)
end = datetime.now()
running_time = end - start
# Summarizing the results of cross-validation
data = opt.to_dict()
data['inner_classifier'] = str(model)
data['datetime'] = datetime.now().strftime("%Y:%m:%d %H:%M:%S")
data['running_time'] = str(running_time.seconds) + " seconds"
data['n_params'] = classifier.count_params()
data['segments_times'] = timedelta(seconds=int(segments_time))
data['segments_overlaps'] = segments_overlap
data['decision_times'] = timedelta(seconds=int(decision_time))
data['decision_overlaps'] = decision_overlap
statistics_summary = {}
for key in statistics.keys():
for inner_key in statistics[key].keys():
statistics_summary[key + '_' + inner_key + '_mean'] = np.average(
statistics[key][inner_key])
statistics_summary[key + '_' + inner_key + '_std'] = np.std(
statistics[key][inner_key])
statistics_summary[key + '_' + inner_key + '_max'] = np.max(
statistics[key][inner_key])
statistics_summary[key + '_' + inner_key + '_min'] = np.min(
statistics[key][inner_key])
data.update(statistics_summary)
# Save information
save_result(log_dir=log_dir, data=data)