コード例 #1
0
ファイル: update_model.py プロジェクト: tuantmb/SecuML
class UpdateModel(CoreUpdateModel):
    def __init__(self, iteration):
        CoreUpdateModel.__init__(self, iteration)
        self.exp = self.iteration.exp
        self.model_exp = None

    def execute(self):
        name = 'AL%d-Iter%d-main' % (self.exp.exp_id, self.iteration.iter_num)
        exp_conf = DiademConf(self.exp.exp_conf.secuml_conf,
                              self.exp.exp_conf.dataset_conf,
                              self.exp.exp_conf.features_conf,
                              self.exp.exp_conf.annotations_conf,
                              self.model_conf,
                              name=name,
                              parent=self.exp.exp_id)
        self.model_exp = DiademExp(exp_conf, session=self.exp.session)
        self.model_exp.run(instances=self.iteration.datasets.instances,
                           cv_monitoring=True)
        self._set_exec_time()
        self.classifier = self.model_exp.get_train_exp().classifier

    def _set_exec_time(self):
        training = self.model_exp.get_train_exp().monitoring
        training_detect = self.model_exp.get_detection_exp('train').monitoring
        detection = self.model_exp.get_detection_exp('test').monitoring
        self.exec_time = sum(
            [m.exec_time for m in [training, training_detect, detection]])

    def monitoring(self, al_dir, iteration_dir):
        with_validation = self.iteration.conf.validation_conf is not None
        self.monitoring = ModelPerfEvolution(self.iteration.iter_num,
                                             self.model_exp, with_validation)
        self.monitoring.generate()
        self.monitoring.export(iteration_dir, al_dir)
コード例 #2
0
class UpdateModel(CoreUpdateModel):
    def __init__(self, iteration):
        CoreUpdateModel.__init__(self, iteration)
        self.exp = self.iteration.exp
        self.model_exp = None

    def execute(self):
        name = 'AL%d-Iter%d-main' % (self.exp.exp_id, self.iteration.iter_num)
        features_conf = FeaturesConf(
            self.exp.exp_conf.features_conf.input_features,
            self.exp.exp_conf.features_conf.sparse,
            self.exp.exp_conf.features_conf.logger,
            filter_in_f=self.exp.exp_conf.features_conf.filter_in_f,
            filter_out_f=self.exp.exp_conf.features_conf.filter_out_f)
        exp_conf = DiademConf(self.exp.exp_conf.secuml_conf,
                              self.exp.exp_conf.dataset_conf,
                              features_conf,
                              self.exp.exp_conf.annotations_conf,
                              self.model_conf,
                              None,
                              name=name,
                              parent=self.exp.exp_id)
        self.model_exp = DiademExp(exp_conf, session=self.exp.session)
        classifier_type = get_classifier_type(
            self.model_conf.classifier_conf.__class__)
        cv_monitoring = classifier_type == ClassifierType.supervised
        prev_classifier = None
        prev_iter = self.iteration.prev_iter
        if prev_iter is not None:
            prev_classifier = prev_iter.update_model.classifier
        self.model_exp.run(instances=self.iteration.datasets.instances,
                           cv_monitoring=cv_monitoring,
                           init_classifier=prev_classifier)
        self._set_exec_time()
        self.classifier = self.model_exp.get_train_exp().classifier

    def _set_exec_time(self):
        training = self.model_exp.get_train_exp().monitoring
        training_detect = self.model_exp.get_detection_exp('train').monitoring
        detection = self.model_exp.get_detection_exp('test').monitoring
        self.exec_time = training.exec_times.total()
        self.exec_time += sum(
            [m.exec_time.predictions for m in [training_detect, detection]])

    def monitoring(self, al_dir, iteration_dir):
        with_validation = self.iteration.conf.validation_conf is not None
        self.monitoring = ModelPerfEvolution(self.iteration.iter_num,
                                             self.model_exp, with_validation)
        self.monitoring.generate()
        self.monitoring.export(iteration_dir, al_dir)
コード例 #3
0
ファイル: aladin.py プロジェクト: zzszmyf/SecuML
 def _run_logistic_regression(self):
     name = '-'.join([
         'AL%d' % (self.exp.exp_id),
         'Iter%d' % (self.iteration.iter_num), 'all', 'LogisticRegression'
     ])
     features_conf = FeaturesConf(
         self.exp.exp_conf.features_conf.input_features,
         self.exp.exp_conf.features_conf.sparse,
         self.exp.exp_conf.features_conf.logger,
         filter_in_f=self.exp.exp_conf.features_conf.filter_in_f,
         filter_out_f=self.exp.exp_conf.features_conf.filter_out_f)
     exp_conf = DiademConf(self.exp.exp_conf.secuml_conf,
                           self.exp.exp_conf.dataset_conf,
                           features_conf,
                           self.exp.exp_conf.annotations_conf,
                           self.exp.exp_conf.core_conf.multiclass_model,
                           None,
                           name=name,
                           parent=self.exp.exp_id)
     model_exp = DiademExp(exp_conf, session=self.exp.session)
     model_exp.run(instances=self.iteration.datasets.instances,
                   cv_monitoring=False)
     train_exp = model_exp.get_train_exp()
     test_exp = model_exp.get_detection_exp('test')
     self.lr_predicted_proba = test_exp.predictions.all_probas
     self.lr_predicted_labels = test_exp.predictions.values
     self.lr_class_labels = train_exp.classifier.class_labels
     self.lr_time = train_exp.monitoring.exec_times.total()
     self.lr_time += test_exp.monitoring.exec_time.predictions