Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mean and std values per metric in CVResult #467

Merged
merged 1 commit into from
Feb 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion cornac/experiment/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,21 @@ class CVResult(list):
----------
model_name: string, required
The name of the recommender model.

Attributes
----------
metric_mean: :obj:`OrderedDict`
A dictionary containing the mean of results across all folds per-metric.

metric_std: :obj:`OrderedDict`
A dictionary containing the standard deviation of results across all folds per-metric.
"""

def __init__(self, model_name):
super().__init__()
self.model_name = model_name
self.metric_mean = OrderedDict()
self.metric_std = OrderedDict()

def __str__(self):
return "[{}]\n{}".format(self.model_name, self.table)
Expand All @@ -99,12 +109,16 @@ def organize(self):

data = np.asarray(data)
mean, std = data.mean(axis=0), data.std(axis=0)

for m, mean_val, std_val in zip(headers, mean, std):
self.metric_mean[m] = mean_val
self.metric_std[m] = std_val

data = np.vstack([data, mean, std])
data = [[NUM_FMT.format(v) for v in row] for row in data]
index.extend(["Mean", "Std"])
self.table = _table_format(data, headers, index, h_bars=[1, len(data) - 1])


class PSTResult(list):
"""
Propensity Stratified Result Class for a single model
Expand Down