Re-group scores respecting M4 rules. :param scores: Scores per group. :return: Grouped scores.
(self, scores)
| 111 | grouped_model_mases) |
| 112 | |
| 113 | def summarize_groups(self, scores): |
| 114 | """ |
| 115 | Re-group scores respecting M4 rules. |
| 116 | :param scores: Scores per group. |
| 117 | :return: Grouped scores. |
| 118 | """ |
| 119 | scores_summary = OrderedDict() |
| 120 | |
| 121 | def group_count(group_name): |
| 122 | return len(np.where(self.test_set.groups == group_name)[0]) |
| 123 | |
| 124 | weighted_score = {} |
| 125 | for g in ['Yearly', 'Quarterly', 'Monthly']: |
| 126 | weighted_score[g] = scores[g] * group_count(g) |
| 127 | scores_summary[g] = scores[g] |
| 128 | |
| 129 | others_score = 0 |
| 130 | others_count = 0 |
| 131 | for g in ['Weekly', 'Daily', 'Hourly']: |
| 132 | others_score += scores[g] * group_count(g) |
| 133 | others_count += group_count(g) |
| 134 | weighted_score['Others'] = others_score |
| 135 | scores_summary['Others'] = others_score / others_count |
| 136 | |
| 137 | average = np.sum(list(weighted_score.values())) / len(self.test_set.groups) |
| 138 | scores_summary['Average'] = average |
| 139 | |
| 140 | return scores_summary |