def get_naive_bayes_conf(self): name = '-'.join([ 'AL%d' % self.exp.exp_id, 'Iter%d' % self.iteration.iter_num, 'all', 'NaiveBayes' ]) classifier_conf = self.exp.exp_conf.core_conf.classifier_conf optim_conf = classifier_conf.hyperparam_conf.optim_conf multiclass = True hyperparam_conf = HyperparamConf.get_default( optim_conf.num_folds, optim_conf.n_jobs, multiclass, GaussianNaiveBayesConf._get_hyper_desc(), self.exp.logger) naive_bayes_conf = GaussianNaiveBayesConf(multiclass, hyperparam_conf, self.exp.logger) test_conf = UnlabeledLabeledConf(self.exp.logger, None) classification_conf = ClassificationConf(naive_bayes_conf, test_conf, self.exp.logger) 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, classification_conf, name=name, parent=self.exp.exp_id) naive_bayes_exp = DiademExp(exp_conf, session=self.exp.session) naive_bayes_exp.create_exp() return naive_bayes_conf
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_test_exp('train').classifier def _set_exec_time(self): train_monitor = self.model_exp.get_train_test_exp('train').monitoring test_monitor = self.model_exp.get_train_test_exp('test').monitoring self.exec_time = sum( [m.exec_time for m in [train_monitor, test_monitor]]) 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)
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 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 get_naive_bayes_conf(self): name = '-'.join([ 'AL%d' % self.exp.exp_id, 'Iter%d' % self.iteration.iter_num, 'all', 'NaiveBayes' ]) classifier_conf = self.exp.exp_conf.core_conf.classifier_conf optim_conf = classifier_conf.hyperparam_conf.optim_conf multiclass = True factory = classifiers.get_factory() naive_bayes_conf = factory.get_default('GaussianNaiveBayes', optim_conf.num_folds, optim_conf.n_jobs, multiclass, self.exp.logger) test_conf = UnlabeledLabeledConf(self.exp.logger) classification_conf = ClassificationConf(naive_bayes_conf, test_conf, self.exp.logger) 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, classification_conf, None, name=name, parent=self.exp.exp_id) DiademExp(exp_conf, session=self.exp.session) return naive_bayes_conf
def _get_multiclass_conf(self): conf = self.rcd_conf.classification_conf name = '-'.join([ 'AL%d' % self.exp.exp_id, 'Iter%d' % self.iteration.iter_num, self.label, 'analysis' ]) 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, conf, name=name, parent=self.exp.exp_id) self.multiclass_exp = DiademExp(exp_conf, session=self.exp.session) self.multiclass_exp.create_exp() return conf
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
def _get_multiclass_conf(self): conf = self.rcd_conf.classification_conf name = '-'.join(['AL%d' % self.exp.exp_id, 'Iter%d' % self.iteration.iter_num, self.label, 'analysis']) 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, conf, None, name=name, parent=self.exp.exp_id) self.multiclass_exp = DiademExp(exp_conf, session=self.exp.session) return conf
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)
class RcdQueries(CoreRcdQueries): def __init__(self, iteration, label, proba_min=None, proba_max=None, input_checking=True): CoreRcdQueries.__init__(self, iteration, label, proba_min, proba_max, input_checking=input_checking) self.multiclass_exp = None self.exp = iteration.exp def generate_query(self, instance_id, predicted_proba, suggested_label, suggested_family, confidence=None): return Query(instance_id, predicted_proba, suggested_label, suggested_family, confidence=confidence) def _get_multiclass_conf(self): conf = self.rcd_conf.classification_conf name = '-'.join([ 'AL%d' % self.exp.exp_id, 'Iter%d' % self.iteration.iter_num, self.label, 'analysis' ]) 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, conf, None, name=name, parent=self.exp.exp_id) self.multiclass_exp = DiademExp(exp_conf, session=self.exp.session) self.multiclass_exp.create_exp() return conf def _create_clustering_exp(self): core_conf = CoreClusteringConf(self.exp.exp_conf.logger, self.categories.num_categories) name = '-'.join([ 'AL%d' % self.exp.exp_id, 'Iter%d' % self.iteration.iter_num, self.label, 'clustering' ]) exp_conf = ClusteringConf(self.exp.exp_conf.secuml_conf, self.exp.exp_conf.dataset_conf, self.exp.exp_conf.features_conf, self.exp.exp_conf.annotations_conf, core_conf, name=name, parent=self.exp.exp_id) clustering_exp = ClusteringExperiment(exp_conf, session=self.exp.session) clustering_exp.create_exp() return clustering_exp def _gen_clustering_visu(self): if self.families_analysis: self.clustering_exp = self._create_clustering_exp() clustering = Clusters(self.categories.instances, self.categories.assigned_categories) clustering.generate(None, None) clustering.export(self.clustering_exp.output_dir()) else: self.clustering_exp = None def _set_categories(self, all_instances, assigned_categories, predicted_proba): self.categories = Categories(self.multiclass_exp, self.iteration, all_instances, assigned_categories, predicted_proba, self.label, self.multiclass_model.class_labels)