def display(self, directory): labels = [ '0-10%', '10-20%', '20-30%', '30-40%', '40-50%', '50-60%', '60-70%', '70-80%', '80-90%', '90-100%' ] barplot = BarPlot(labels) barplot.addDataset(map(len, self.ranges), colors_tools.getLabelColor('all'), 'numInstances') filename = directory + 'predictions_barplot.json' with open(filename, 'w') as f: barplot.display(f) barplot = BarPlot(labels) malicious_ranges = map(lambda l: filter(lambda x: x['true_label'], l), self.ranges) benign_ranges = map(lambda l: filter(lambda x: not x['true_label'], l), self.ranges) barplot.addDataset(map(len, malicious_ranges), colors_tools.getLabelColor('malicious'), 'malicious') barplot.addDataset(map(len, benign_ranges), colors_tools.getLabelColor('benign'), 'benign') filename = directory filename += 'predictions_barplot_labels.json' with open(filename, 'w') as f: barplot.display(f)
def plotEvolutionMonitoring(self): barplot = BarPlot(self.families) for i in range(self.data.shape[0]): barplot.addDataset(list(self.data.iloc[i, 1:]), 'blue', str(i)) filename = self.output_directory filename += self.label + '_families_evolution.json' with open(filename, 'w') as f: barplot.display(f)
def generateBinaryHistogram(self): barplot = BarPlot(['0', '1']) for label, dataset in self.plot_datasets.iteritems(): num_0 = sum(dataset.values == 0) num_1 = sum(dataset.values == 1) barplot.addDataset([num_0, num_1], dataset.color, dataset.label) output_filename = self.output_directory + 'binary_histogram.json' with open(output_filename, 'w') as f: barplot.display(f)
def generateHistogram(self): # 10 equal-width bins computed on all the data if not self.has_true_labels: hist, bin_edges = np.histogram(self.plot_datasets['all'].values, bins=10, density=False) else: hist, bin_edges = np.histogram( self.plot_datasets['malicious'].values, bins=10, density=False) x_labels = [ str(bin_edges[e]) + ' - ' + str(bin_edges[e + 1]) for e in range(len(bin_edges) - 1) ] barplot = BarPlot(x_labels) for label, dataset in self.plot_datasets.iteritems(): hist, bin_edges = np.histogram(dataset.values, bins=bin_edges, density=False) barplot.addDataset(hist, dataset.color, dataset.label) output_filename = self.output_directory + 'histogram.json' with open(output_filename, 'w') as f: barplot.display(f)