class NaiveBayesClassifierTests(TestCase): """Tests for the NaiveBayesClassifier class.""" def setUp(self): """Define some sample data that will be used by the tests.""" self.ref_seqs1 = StringIO(ref_seqs1) self.tax_map1 = StringIO(tax_map1) self.training_data1 = StringIO(training_data1) self.classifier = NaiveBayesClassifier(ref_seqs_f=self.ref_seqs1, tax_map_f=self.tax_map1) self.ref_seqs_tiny = StringIO(ref_seqs_tiny) self.tax_map_tiny = StringIO(tax_map_tiny) self.classifier_ws1 = NaiveBayesClassifier( ref_seqs_f=self.ref_seqs_tiny, tax_map_f=self.tax_map_tiny, WordSize=1) def test_init(self): """Test raises error on invalid constructor arguments.""" self.assertRaises(MissingTrainingSetError, NaiveBayesClassifier) self.assertRaises(AmbiguousTrainingSetError, NaiveBayesClassifier, ref_seqs_f=self.ref_seqs1, tax_map_f=self.tax_map1, training_data_f=self.training_data1) def test_call(self): """Test classifying sequences.""" obs = self.classifier(self.ref_seqs1) #self.assertEqual(obs, exp_classifications1) def test_calculate_prior_word_probabilities(self): """Test calculating probability of seeing words in training set.""" self.classifier_ws1._calculate_prior_word_probabilities() self.assertFloatEqual(self.classifier_ws1._prior_word_probabilities, {'A': 0.83333333, 'T': 0.83333333, 'G': 0.5, 'C': 0.16666667})
def setUp(self): """Define some sample data that will be used by the tests.""" self.ref_seqs1 = StringIO(ref_seqs1) self.tax_map1 = StringIO(tax_map1) self.training_data1 = StringIO(training_data1) self.classifier = NaiveBayesClassifier(ref_seqs_f=self.ref_seqs1, tax_map_f=self.tax_map1) self.ref_seqs_tiny = StringIO(ref_seqs_tiny) self.tax_map_tiny = StringIO(tax_map_tiny) self.classifier_ws1 = NaiveBayesClassifier( ref_seqs_f=self.ref_seqs_tiny, tax_map_f=self.tax_map_tiny, WordSize=1)