def __filter_output_data(self, classes_to_visualise):
        """
        Filter the output or input data corresponding to the classes to visualise.

        @param classes_to_visualise: A list containing names for the classes to visualise.
        """
        class_names = get_all_class_names()
        class_indices_to_visualise = []
        for i in range(len(class_names)):
            if class_names[i] in classes_to_visualise:
                class_indices_to_visualise.append(i)

        if not len(class_indices_to_visualise) == len(classes_to_visualise):
            print 'Not all classes to visualise were correct.'
            return

        tmp_output_data = []
        tmp_class_indices = []
        for i in range(len(self.output_data)):
            out = self.output_data[i]
            idx = self.class_indices[i]
            if idx in class_indices_to_visualise:
                tmp_output_data.append(out)
                tmp_class_indices.append(idx)

        self.output_data = tmp_output_data
        self.class_indices = tmp_class_indices
Beispiel #2
0
    def confusion_matrix(self, no_of_neighbors):
        evaluated_class_indices = self.k_nearest_neibors(no_of_neighbors)
        font = {'family': 'normal',
                'weight': 'bold',
                'size': 16}
        matplotlib.rc('font', **font)

        lbls = get_all_class_names()
        for i in range(len(lbls)):
            if len(lbls[i]) > 12:
                str = lbls[i][:10]
                lbls[i] = str + "..."
        cm = confusion_matrix(self.class_indices, evaluated_class_indices, sorted(set(self.class_indices)))
        # Show confusion matrix
        fig = plot.figure()
        ax = fig.add_subplot(111)
        cax = ax.matshow(cm)
        fig.colorbar(cax)
        ax.set_xticklabels([''] + lbls)
        plot.xticks(rotation=55)
        ax.set_yticklabels([''] + lbls)
        plot.yticks(rotation=55)
        plot.ylabel('True label')
        plot.xlabel('Predicted label')
        plot.show()
Beispiel #3
0
    def __filter_output_data(self, classes_to_visualise):
        """
        Filter the output or input data corresponding to the classes to visualise.

        @param classes_to_visualise: A list containing names for the classes to visualise.
        """
        class_names = get_all_class_names()
        class_indices_to_visualise = []
        for i in range(len(class_names)):
            if class_names[i] in classes_to_visualise:
                class_indices_to_visualise.append(i)

        if not len(class_indices_to_visualise) == len(classes_to_visualise):
            print 'Not all classes to visualise were correct.'
            return

        tmp_output_data = []
        tmp_class_indices = []
        for i in range(len(self.output_data)):
            out = self.output_data[i]
            idx = self.class_indices[i]
            if idx in class_indices_to_visualise:
                tmp_output_data.append(out)
                tmp_class_indices.append(idx)

        self.output_data = tmp_output_data
        self.class_indices = tmp_class_indices