def run(self, train_instances, cv_monitoring=False): Experiment.run(self) self._train(train_instances) if cv_monitoring: self._cv_monitoring(train_instances) else: self.cv_monitoring = None self._export()
def add_to_db(self): from secuml.exp.diadem import add_diadem_exp_to_db Experiment.add_to_db(self) add_diadem_exp_to_db(self.session, self.exp_conf.exp_id, self.exp_conf.fold_id, 'train', classifier_conf=self.exp_conf.core_conf)
def run(self, instances=None, drop_annotated_instances=False, quick=False): Experiment.run(self) instances = self.get_instances() core_conf = self.exp_conf.core_conf clustering = core_conf.algo(instances, core_conf) clustering.fit() clustering.generate(drop_annotated_instances=drop_annotated_instances) clustering.export(self.output_dir(), quick=quick)
def __init__(self, exp_conf, create=True, session=None): self.kind = exp_conf.kind Experiment.__init__(self, exp_conf, create=create, session=session) self.test_instances = None self.predictions = None self.prediction_time = None self.classifier = None alerts_conf = self.exp_conf.core_conf self.monitoring = DetectionMonitoring(self, alerts_conf=alerts_conf)
def add_to_db(self): Experiment.add_to_db(self) from secuml.exp.diadem import add_diadem_exp_to_db add_diadem_exp_to_db(self.session, self.exp_conf.exp_id, self.exp_conf.fold_id, self.kind, alerts_conf=self.alerts_conf, classifier_conf=self.exp_conf.core_conf)
def set_clusters(self, instances, assigned_clusters, centroids, drop_annotated_instances, cluster_labels): Experiment.run(self) clustering = Clusters(instances, assigned_clusters) clustering.generate(centroids, drop_annotated_instances=drop_annotated_instances, cluster_labels=cluster_labels) clustering.export(self.output_dir(), drop_annotated_instances=drop_annotated_instances)
def add_to_db(self): Experiment.add_to_db(self) features_set_id = self.exp_conf.features_conf.set_id annotations_file = self.exp_conf.annotations_conf.annotations_filename stats_exp = FeaturesAnalysisExpAlchemy( id=self.exp_id, features_set_id=features_set_id, annotations_filename=annotations_file) self.session.add(stats_exp) self.session.flush()
def add_to_db(self): Experiment.add_to_db(self) has_ground_truth = self.exp_conf.dataset_conf.has_ground_truth dataset_id = self.exp_conf.dataset_conf.dataset_id self.session.add( DiademExpAlchemy(exp_id=self.exp_conf.exp_id, dataset_id=dataset_id, fold_id=self.exp_conf.fold_id, type=self.kind, perf_monitoring=has_ground_truth)) self.session.flush()
def __init__(self, exp_conf, classifier=None, alerts_conf=None, create=True, session=None): self.classifier = classifier self.kind = exp_conf.kind self.alerts_conf = alerts_conf self.test_instances = None self.predictions = None self.monitoring = None Experiment.__init__(self, exp_conf, create=create, session=session)
def run(self): Experiment.run(self) instances = self.get_instances() with_density = instances.num_instances() < 150000 if not with_density: self.exp_conf.logger.warning('There are more than 150.000, so ' 'the density plots are not ' 'displayed. ') stats = FeaturesAnalysis(instances, self.exp_conf.multiclass, self.exp_conf.logger, with_density=with_density) stats.gen_plots(self.output_dir()) stats.gen_scoring(self.output_dir())
def run(self, instances=None, export=True): Experiment.run(self) instances = self.get_instances() core_conf = self.exp_conf.core_conf dimension_reduction = core_conf.algo(core_conf) # Fit dimension_reduction.fit(instances) if export: dimension_reduction.export_fit(self.output_dir(), instances) # Transformation projected_instances = dimension_reduction.transform(instances) if export: dimension_reduction.export_transform(self.output_dir(), instances, projected_instances) return projected_instances
def run(self): Experiment.run(self) datasets = Datasets(self.get_instances()) active_learning = ActiveLearning(self, datasets) if not self.exp_conf.core_conf.auto: from secuml.exp.celery_app.app import secumlworker from secuml.exp.active_learning.celery_tasks import IterationTask options = {} # bind iterations object to IterationTask class active_learning.run_next_iter(output_dir=self.output_dir()) IterationTask.iteration_object = active_learning # Start worker secumlworker.enable_config_fromcmdline = False secumlworker.run(**options) else: active_learning.run_iterations(output_dir=self.output_dir())
def create_exp(self): Experiment.create_exp(self) # create projection experiment self.projection_exp = None if self.exp_conf.core_conf is None: return projection_core_conf = self.exp_conf.core_conf.projection_conf if projection_core_conf is not None: features_conf = FeaturesConf( self.exp_conf.features_conf.input_features, self.exp_conf.secuml_conf.logger) projection_conf = ProjectionConf(self.exp_conf.secuml_conf, self.exp_conf.dataset_conf, features_conf, self.exp_conf.annotations_conf, projection_core_conf, name='-'.join( [self.exp_conf.name, 'proj']), parent=self.exp_id) self.projection_exp = ProjectionExperiment(projection_conf, session=self.session)
def get_instances(self, instances=None): instances = Experiment.get_instances(self, instances=instances) if self.exp_conf.label != 'all': selected_ids = instances.ground_truth.get_annotated_ids( label=self.exp_conf.label) instances = instances.get_from_ids(selected_ids) if self.projection_exp is not None: try: instances = self.projection_exp.run(instances=instances, export=False) except FewerThanTwoLabels: self.conf.logger.warning('There are too few class labels.' 'The instances are not projected ' 'before building the clustering.') return instances
def __init__(self, exp_conf, create=True, session=None): Experiment.__init__(self, exp_conf, create=create, session=session) self.classifier = None self.train_time = None self.monitoring = TrainMonitoring(self)
def add_to_db(self): Experiment.add_to_db(self) al_exp = ActiveLearningExpAlchemy(id=self.exp_id, current_iter=0, finished=False) self.session.add(al_exp) self.session.flush()
def run(self): Experiment.run(self) stats = FeaturesAnalysis(self.get_instances()) stats.compute() stats.export(self.output_dir())
def run(self, classifier, test_instances): Experiment.run(self) self.test_instances = self.get_instances(test_instances) self.classifier = classifier self._test() self._export()
def __init__(self, exp_conf, create=True, session=None): Experiment.__init__(self, exp_conf, create=create, session=session) self.classifier = None self.predictions = None self.monitoring = None self.cv_monitoring = None
def __init__(self, exp_conf, create=True, session=None): Experiment.__init__(self, exp_conf, create, session) self.test_conf = self.exp_conf.core_conf.test_conf self.validation_conf = self.exp_conf.core_conf.validation_conf self._train_test_exps = {}
def add_to_db(self): Experiment.add_to_db(self) self.session.add(DiademExpAlchemy(exp_id=self.exp_conf.exp_id, fold_id=self.exp_conf.fold_id, type=self.kind)) self.session.flush()
def run(self, train_instances, cv_monitoring=False): Experiment.run(self) self._train(train_instances) if cv_monitoring: self._cv_monitoring(train_instances) self.monitoring.display(self.output_dir())
def run(self, test_instances): Experiment.run(self) self.test_instances = self.get_instances(test_instances) self._test() self._export()