-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrainEnsemble.py
More file actions
30 lines (24 loc) · 876 Bytes
/
trainEnsemble.py
File metadata and controls
30 lines (24 loc) · 876 Bytes
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
from core.config import cfg, update_cfg
from core.GNNs.ensemble_trainer import EnsembleTrainer
import pandas as pd
import time
def run(cfg):
seeds = [cfg.seed] if cfg.seed is not None else range(cfg.runs)
all_acc = []
start = time.time()
for seed in seeds:
cfg.seed = seed
ensembler = EnsembleTrainer(cfg)
acc = ensembler.train()
all_acc.append(acc)
end = time.time()
if len(all_acc) > 1:
df = pd.DataFrame(all_acc)
for f in df.keys():
df_ = pd.DataFrame([r for r in df[f]])
print(
f"[{f}] ValACC: {df_['val_acc'].mean():.4f} ± {df_['val_acc'].std():.4f}, TestAcc: {df_['test_acc'].mean():.4f} ± {df_['test_acc'].std():.4f}")
print(f"Running time: {round((end-start)/len(seeds), 2)}s")
if __name__ == '__main__':
cfg = update_cfg(cfg)
run(cfg)