Пример #1
0
 def runNaiveBayes(self):
     # Create an experiment for the naive Bayes model
     exp = self.iteration.experiment
     name = '-'.join([
         'AL' + str(exp.experiment_id),
         'Iter' + str(self.iteration.iteration_number), 'all', 'NaiveBayes'
     ])
     naive_bayes_exp = ClassificationExperiment(
         exp.project,
         exp.dataset,
         exp.db,
         exp.cursor,
         experiment_name=name,
         experiment_label=exp.experiment_label,
         parent=exp.experiment_id)
     naive_bayes_exp.setFeaturesFilenames(exp.features_filenames)
     test_conf = TestConfiguration()
     test_conf.setUnlabeled(labels_annotations='annotations')
     naive_bayes_conf = GaussianNaiveBayesConfiguration(
         exp.conf.models_conf['multiclass'].num_folds, False, True,
         test_conf)
     naive_bayes_exp.setClassifierConf(naive_bayes_conf)
     naive_bayes_exp.createExperiment()
     naive_bayes_exp.export()
     # Update training data - the naive Bayes classifier is trained on all the data
     self.datasets.test_instances.families = list(self.lr_predicted_labels)
     all_datasets = ClassifierDatasets(naive_bayes_exp,
                                       naive_bayes_exp.classification_conf)
     train_instances = Instances()
     train_instances.union(self.datasets.train_instances,
                           self.datasets.test_instances)
     all_datasets.train_instances = train_instances
     all_datasets.test_instances = None
     all_datasets.setSampleWeights()
     self.evalClusteringPerf(all_datasets.train_instances)
     # Train the naive Bayes detection model and predict
     self.naive_bayes = GaussianNaiveBayes(naive_bayes_exp, all_datasets)
     self.naive_bayes.training()
     self.nb_time = self.naive_bayes.training_execution_time
     self.datasets.test_instances.families = [
         None
     ] * self.datasets.test_instances.numInstances()
     self.nb_predicted_log_proba = self.naive_bayes.pipeline.predict_log_proba(
         self.datasets.test_instances.getFeatures())
     start_time = time.time()
     self.nb_predicted_labels = self.naive_bayes.pipeline.predict(
         self.datasets.test_instances.getFeatures())
     self.nb_time += time.time() - start_time
     self.nb_class_labels = self.naive_bayes.class_labels
 def createNaiveBayesConf(self):
     exp = self.experiment
     name = '-'.join(['AL' + str(exp.experiment_id),
         'Iter' + str(self.iteration.iteration_number),
         'all',
         'NaiveBayes'])
     naive_bayes_exp = ClassificationExperiment(exp.project, exp.dataset, exp.session,
                                                experiment_name = name,
                                                labels_id = exp.labels_id,
                                                parent = exp.experiment_id)
     naive_bayes_exp.setFeaturesFilenames(exp.features_filenames)
     test_conf = TestConfiguration()
     test_conf.setUnlabeled(labels_annotations = 'annotations')
     naive_bayes_conf = GaussianNaiveBayesConfiguration(exp.conf.models_conf['multiclass'].num_folds, False, True, test_conf)
     naive_bayes_exp.setClassifierConf(naive_bayes_conf)
     naive_bayes_exp.createExperiment()
     naive_bayes_exp.export()
     return naive_bayes_conf
Пример #3
0
 def createNaiveBayesConf(self):
     test_conf = TestConfiguration()
     test_conf.setUnlabeled(labels_annotations='annotations')
     naive_bayes_conf = GaussianNaiveBayesConfiguration(
         4, False, True, test_conf)
     return naive_bayes_conf