-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added missing results tracking file.
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |