Ejemplo n.º 1
0
def plot_results(data, type=None):
    import numpy as np
    import matplotlib.pyplot as plt

    for context in data['ctx'].keys():
        labels = []
        baseline_metrics = (data['ctx'][context]['2d']['Precision'], data['ctx'][context]['2d']['Recall'], data['ctx'][context]['2d']['F1-score'])
        contextual_metrics = AutoVivification()

        labels.extend(['Baseline', 'Baseline', 'Baseline'])

        for condition in data['ctx'][context].keys():
            if condition == '2d':
                continue
            contextual_metrics[condition] = (data['ctx'][context][condition]['Precision'],
                                             data['ctx'][context][condition]['Recall'],
                                             data['ctx'][context][condition]['F1-score'])

            label_name = ContextConditionMappings[context][int(condition)]
            labels.extend([label_name, label_name, label_name])
        print baseline_metrics
        print contextual_metrics

        fig, ax = plt.subplots()
        index = np.arange(3)
        bar_width = 0.15
        opacity = 0.8

        rects1 = plt.bar(index, baseline_metrics, bar_width,
                         alpha=opacity,
                         color='b',
                         label='Baseline')
        colors = {
            '1': 'r',
            '2': 'g',
            '3': 'y',
            '4': 'c',
            '5': 'm',
            '6': 'k',
            '7': '#ee1f3f',
            '8': '#123ef2'
        }
        i = 1
        for condition in contextual_metrics.keys():
            plt.bar(index + bar_width * i, contextual_metrics[condition], bar_width,
                    alpha=opacity,
                    color=colors[condition],
                    label=ContextConditionMappings[context][int(condition)])
            i += 1

        rects = ax.patches
        # Now make some labels
        # labels = ["label%d" % i for i in xrange(len(rects))]
        for rect, label in zip(rects, labels):
            height = rect.get_height()
            ax.text(rect.get_x() + rect.get_width() / 2, height, label, ha='center', va='bottom')

        # plt.xlabel('Metric')
        # plt.ylabel('Value')
        plt.title('Evaluation Metrics for ' + ContextMappings[context] + ' context')
        plt.xticks(index + bar_width + 0.15, ('Precision', 'Recall', 'F1Score'))
        plt.legend()
        plt.tight_layout()
        plt.show()
Ejemplo n.º 2
0
    def plot(self):
        import numpy as np
        import matplotlib.pyplot as plt

        for context in self.metrics.keys():
            labels = []
            baseline_metrics = (self.metrics[context][self.metrics[context].keys()[0]]['precision'],
                                self.metrics[context][self.metrics[context].keys()[0]]['recall'],
                                self.metrics[context][self.metrics[context].keys()[0]]['f1Score'])
            contextual_metrics = AutoVivification()
            labels.extend(['Baseline', 'Baseline', 'Baseline'])

            for condition in self.metrics[context].keys():
                contextual_metrics[condition] = (self.metrics[context][condition]['precision-ctx'],
                                                 self.metrics[context][condition]['recall-ctx'],
                                                 self.metrics[context][condition]['f1Score-ctx'])

                labels.extend([condition, condition, condition])
            fig, ax = plt.subplots()
            index = np.arange(3)
            bar_width = 0.15
            opacity = 0.8

            rects1 = plt.bar(index, baseline_metrics, bar_width,
                             alpha=opacity,
                             color='b',
                             label='Baseline')
            colors = {
                'Weekend': 'y',
                'Weekday': 'c',
                'Home': 'y',
                'Cinema': 'c',
                'Alone': 'y',
                'Partner': 'c',
                'Family': '#ee1f3f',
            }
            i = 1
            for condition in contextual_metrics.keys():
                plt.bar(index + bar_width * i, contextual_metrics[condition], bar_width,
                        alpha=opacity,
                        color=colors[condition],
                        label=condition)
                i += 1

            rects = ax.patches
            # Now make some labels
            # labels = ["label%d" % i for i in xrange(len(rects))]
            for rect, label in zip(rects, labels):
                height = rect.get_height()
                # ax.text(rect.get_x() + rect.get_width() / 2, height, None, ha='center', va='bottom')

            # plt.xlabel('Metric')
            # plt.ylabel('Value')
            plt.title('Evaluation Metrics for ' + context)
            plt.xticks(index + bar_width + 0.15, ('Precision', 'Recall', 'F1Score'))

            import math
            plt.ylim([0, 1])
            plt.legend()
            plt.tight_layout()
            plt.show()
Ejemplo n.º 3
0
    def plot(self):
        import numpy as np
        import matplotlib.pyplot as plt

        for context in self.metrics.keys():
            labels = []
            baseline_metrics = (self.metrics[context][
                self.metrics[context].keys()[0]]['precision'],
                                self.metrics[context][
                                    self.metrics[context].keys()[0]]['recall'],
                                self.metrics[context]
                                [self.metrics[context].keys()[0]]['f1Score'])
            contextual_metrics = AutoVivification()
            labels.extend(['Baseline', 'Baseline', 'Baseline'])

            for condition in self.metrics[context].keys():
                contextual_metrics[condition] = (
                    self.metrics[context][condition]['precision-ctx'],
                    self.metrics[context][condition]['recall-ctx'],
                    self.metrics[context][condition]['f1Score-ctx'])

                labels.extend([condition, condition, condition])
            fig, ax = plt.subplots()
            index = np.arange(3)
            bar_width = 0.15
            opacity = 0.8

            rects1 = plt.bar(index,
                             baseline_metrics,
                             bar_width,
                             alpha=opacity,
                             color='b',
                             label='Baseline')
            colors = {
                'Weekend': 'y',
                'Weekday': 'c',
                'Home': 'y',
                'Cinema': 'c',
                'Alone': 'y',
                'Partner': 'c',
                'Family': '#ee1f3f',
            }
            i = 1
            for condition in contextual_metrics.keys():
                plt.bar(index + bar_width * i,
                        contextual_metrics[condition],
                        bar_width,
                        alpha=opacity,
                        color=colors[condition],
                        label=condition)
                i += 1

            rects = ax.patches
            # Now make some labels
            # labels = ["label%d" % i for i in xrange(len(rects))]
            for rect, label in zip(rects, labels):
                height = rect.get_height()
                # ax.text(rect.get_x() + rect.get_width() / 2, height, None, ha='center', va='bottom')

            # plt.xlabel('Metric')
            # plt.ylabel('Value')
            plt.title('Evaluation Metrics for ' + context)
            plt.xticks(index + bar_width + 0.15,
                       ('Precision', 'Recall', 'F1Score'))

            import math
            plt.ylim([0, 1])
            plt.legend()
            plt.tight_layout()
            plt.show()