def test_update(self): b = Bayes([1, 2]) b.update((2, 1)) self.assertEqual(b, [1, 1]) b.update((2, 1)) self.assertEqual(b, [2, 1]) b.update((2, 0)) self.assertEqual(b, [1, 0])
def test_update(self): b = Bayes([1, 2]) b.update((2, 1)) self.assertEqual(b, [1, 1]) b.update((2, 1)) self.assertEqual(b, [2, 1]) b.update((2, 0)) self.assertEqual(b, [1, 0])
# you have directories with examples of each language. #print classify_file("unknown_file", ["java_files", "python_files"]) # Classifies every file under "folder" as either a Python or Java file, # considering you have subdirectories with examples of each language. #print classify_folder("folder") print('') print(' == Low Level Functions == ') print(' -- Classic Cancer Test Problem --') # 1% chance of having cancer. b = Bayes([('not cancer', 0.99), ('cancer', 0.01)]) # Test positive, 9.6% false positives and 80% true positives b.update((9.6, 80)) print(b) print('Most likely:', b.most_likely()) print('') print(' -- Spam Filter With Existing Model --') # Database with number of sightings of each words in (genuine, spam) # emails. words_odds = {'buy': (5, 100), 'viagra': (1, 1000), 'meeting': (15, 2)} # Emails to be analyzed. emails = [ "let's schedule a meeting for tomorrow", # 100% genuine (meeting) "buy some viagra", # 100% spam (buy, viagra) "buy coffee for the meeting", # buy x meeting, should be genuine ]
# you have directories with examples of each language. #print classify_file("unknown_file", ["java_files", "python_files"]) # Classifies every file under "folder" as either a Python or Java file, # considering you have subdirectories with examples of each language. #print classify_folder("folder") print('') print(' == Low Level Functions == ') print(' -- Classic Cancer Test Problem --') # 1% chance of having cancer. b = Bayes([('not cancer', 0.99), ('cancer', 0.01)]) # Test positive, 9.6% false positives and 80% true positives b.update((9.6, 80)) print(b) print('Most likely:', b.most_likely()) print('') print(' -- Spam Filter With Existing Model --') # Database with number of sightings of each words in (genuine, spam) # emails. words_odds = {'buy': (5, 100), 'viagra': (1, 1000), 'meeting': (15, 2)} # Emails to be analyzed. emails = [ "let's schedule a meeting for tomorrow", # 100% genuine (meeting) "buy some viagra", # 100% spam (buy, viagra) "buy coffee for the meeting", # buy x meeting, should be genuine ]