Skip to content

Commit 9888130

Browse files
authored
Add mean and std values per metric in CVResult (#467)
1 parent 2de81e1 commit 9888130

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

cornac/experiment/result.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,21 @@ class CVResult(list):
8181
----------
8282
model_name: string, required
8383
The name of the recommender model.
84+
85+
Attributes
86+
----------
87+
metric_mean: :obj:`OrderedDict`
88+
A dictionary containing the mean of results across all folds per-metric.
89+
90+
metric_std: :obj:`OrderedDict`
91+
A dictionary containing the standard deviation of results across all folds per-metric.
8492
"""
8593

8694
def __init__(self, model_name):
8795
super().__init__()
8896
self.model_name = model_name
97+
self.metric_mean = OrderedDict()
98+
self.metric_std = OrderedDict()
8999

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

100110
data = np.asarray(data)
101111
mean, std = data.mean(axis=0), data.std(axis=0)
112+
113+
for m, mean_val, std_val in zip(headers, mean, std):
114+
self.metric_mean[m] = mean_val
115+
self.metric_std[m] = std_val
116+
102117
data = np.vstack([data, mean, std])
103118
data = [[NUM_FMT.format(v) for v in row] for row in data]
104119
index.extend(["Mean", "Std"])
105120
self.table = _table_format(data, headers, index, h_bars=[1, len(data) - 1])
106121

107-
108122
class PSTResult(list):
109123
"""
110124
Propensity Stratified Result Class for a single model

0 commit comments

Comments
 (0)