Example #1
0
 def display(self, directory):
     barplot = BarPlot(self.labels)
     if not self.has_ground_truth:
         self.display_label(barplot, 'all')
     else:
         self.display_label(barplot, MALICIOUS)
         self.display_label(barplot, BENIGN)
     barplot.export_to_json(path.join(directory, 'proba_barplot.json'))
Example #2
0
 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)
     if not self.has_ground_truth:
         dataset = PlotDataset(list(map(len, self.ranges)), 'num_instances')
         dataset.set_color(get_label_color('all'))
         barplot.add_dataset(dataset)
     else:
         self.display_label(barplot, MALICIOUS)
         self.display_label(barplot, BENIGN)
     barplot.export_to_json(path.join(directory, 'predictions_barplot.json'))
Example #3
0
 def display(self, directory):
     labels = list(self.predictions.keys())
     if self.multiclass:
         xlabels = labels
     else:
         xlabels = [label_bool_to_str(l) for l in labels]
     barplot = BarPlot(xlabels)
     if not self.has_ground_truth:
         self._display(barplot, labels)
     else:
         self._display(barplot, labels, error=False)
         self._display(barplot, labels, error=True)
     barplot.export_to_json(path.join(directory, 'pred_barplot.json'))
Example #4
0
 def to_barplot(self, directory):
     head_coeff = self.coef_summary.head(n=NUM_COEFF_EXPORT)
     coefficients = head_coeff['mean'].values
     features_ids = list(head_coeff.index)
     features_names = []
     user_ids = []
     for feature_id in features_ids:
         query = self.exp.session.query(FeaturesAlchemy)
         query = query.filter(FeaturesAlchemy.id == int(feature_id))
         row = query.one()
         features_names.append(row.name)
         user_ids.append(row.user_id)
     barplot = BarPlot(user_ids)
     dataset = PlotDataset(coefficients, None)
     score = self.classifier_conf.get_feature_importance()
     if score == 'weight':
         dataset.set_color(red)
     else:
         dataset.set_color(blue)
     barplot.add_dataset(dataset)
     if self.class_label is None:
         out_filename = 'coeff_barplot.json'
     else:
         out_filename = 'coeff_barplot_%s.json' % self.class_label
     return barplot.export_to_json(path.join(directory, out_filename),
                                   tooltip_data=features_names)