Skip to content

Commit

Permalink
Added missing results tracking file.
Browse files Browse the repository at this point in the history
  • Loading branch information
kostasde committed Feb 25, 2021
1 parent f3b2721 commit 5a6f493
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions result_tracking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import tqdm
import pandas as pd

from dn3.trainable.processes import BaseProcess
from dn3.data.dataset import Dataset, Thinker


class ThinkerwiseResultTracker:

def __init__(self):
"""
Track the performance of :any:`Thinker`(s) under a certain process.
"""
self._sheets = dict()

def _update_sheet(self, ds_name, summary):
if ds_name not in self._sheets:
self._sheets[ds_name] = list()
self._sheets[ds_name].append(summary)

def add_results_thinker(self, process: BaseProcess, ds_name: str, thinker: Thinker, **kwargs):
metrics = process.evaluate(thinker)
summary = {'Person': str(thinker.person_id),
'Dataset': ds_name,
**metrics,
**kwargs}
self._update_sheet(ds_name, summary)

def add_results_all_thinkers(self, process: BaseProcess, ds_name: str, fold_dataset: Dataset, **kwargs):
for _, _, test_thinker in tqdm.tqdm(fold_dataset.loso(), total=len(fold_dataset.thinkers)):
self.add_results_thinker(process, ds_name, test_thinker, **kwargs)

def performance_summary(self, ds_name):
if ds_name not in self._sheets:
print("Could not find {} to create performance summary.".format(ds_name))
tqdm.tqdm.write(str(pd.DataFrame(self._sheets[ds_name]).describe()))

def to_spreadsheet(self, filename: str):
with pd.ExcelWriter(filename) as writer:
print("Opened", filename)
for ds_name in self._sheets:
df = pd.DataFrame(self._sheets[ds_name])
df.to_excel(writer, sheet_name=ds_name, header=True, index=False)
print("Wrote results for {}...".format(ds_name))

0 comments on commit 5a6f493

Please sign in to comment.