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) dataset = PlotDataset(map(len, self.ranges), 'numInstances') dataset.setColor(colors_tools.getLabelColor('all')) barplot.addDataset(dataset) filename = directory + 'predictions_barplot.json' with open(filename, 'w') as f: barplot.exportJson(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) malicious_dataset = PlotDataset(map(len, malicious_ranges), 'malicious') malicious_dataset.setColor(colors_tools.getLabelColor('malicious')) barplot.addDataset(malicious_dataset) benign_dataset = PlotDataset(map(len, benign_ranges), 'benign') benign_dataset.setColor(colors_tools.getLabelColor('benign')) barplot.addDataset(benign_dataset) filename = directory filename += 'predictions_barplot_labels.json' with open(filename, 'w') as f: barplot.exportJson(f)
def plotEvolutionMonitoring(self): barplot = BarPlot(self.families) for i in range(self.data.shape[0]): dataset = PlotDataset([self.data.iloc[i, 1]], str(i)) barplot.addDataset(dataset) filename = self.output_directory filename += self.label + '_families_evolution.json' with open(filename, 'w') as f: barplot.exportJson(f)
def plotEvolutionMonitoring(self, evolution_file, monitoring_dir): data = self.loadEvolutionMonitoring(evolution_file) barplot = BarPlot(self.families) for i in range(data.shape[0]): dataset = PlotDataset([data.iloc[i, 1]], str(i)) barplot.addDataset(dataset) filename = monitoring_dir filename += self.label + '_families_evolution.json' with open(filename, 'w') as f: barplot.exportJson(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) hist_dataset = PlotDataset([num_0, num_1], dataset.label) hist_dataset.setColor(dataset.color) barplot.addDataset(hist_dataset) output_filename = self.output_directory + 'binary_histogram.json' with open(output_filename, 'w') as f: barplot.exportJson(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) hist_dataset = PlotDataset(hist, dataset.label) hist_dataset.setColor(dataset.color) barplot.addDataset(hist_dataset) output_filename = self.output_directory + 'histogram.json' with open(output_filename, 'w') as f: barplot.exportJson(f)