def test_single(self): self.assertEqual(classify_normal({'a': 100}, {'A': [{'a': 100}]}), 'A') self.assertEqual( classify_normal({ 'a': 100, 'b': 0 }, {'A': [{ 'a': 100, 'b': 0 }]}), 'A') self.assertEqual( classify_normal({ 'a': 100, 'b': 0 }, { 'A': [{ 'a': 100, 'b': 10 }], 'B': [{ 'a': 50, 'b': 100 }] }), None)
def test_single(self): self.assertEqual(classify_normal({'a': 100}, {'A': [{'a': 100}]}), 'A') self.assertEqual(classify_normal({'a': 100, 'b': 0}, {'A': [{'a': 100, 'b': 0}]}), 'A') self.assertEqual(classify_normal({'a': 100, 'b': 0}, {'A': [{'a': 100, 'b': 10}], 'B': [{'a': 50, 'b': 100}]}), None)
def test_sample(self): instance = {'height': 6, 'weight': 130, 'foot size': 8} training = {'male': [{'height': 6, 'weight': 180, 'foot size': 12}, {'height': 5.92, 'weight': 190, 'foot size': 11}, {'height': 5.58, 'weight': 170, 'foot size': 12}, {'height': 5.92, 'weight': 165, 'foot size': 10}], 'female': [{'height': 5, 'weight': 100, 'foot size': 6}, {'height': 5.5, 'weight': 150, 'foot size': 8}, {'height': 5.42, 'weight': 130, 'foot size': 7}, {'height': 5.75, 'weight': 150, 'foot size': 9}]} self.assertEqual(classify_normal(instance, training), 'female')
def test_basic(self): self.assertEqual( classify_normal({ 'a': 100, 'b': 0 }, { 'A': [{ 'a': 100, 'b': 10 }, { 'a': 99, 'b': -10 }], 'B': [{ 'a': 50, 'b': 100 }, { 'a': 70, 'b': 90 }] }), 'A')
def test_sample(self): instance = {'height': 6, 'weight': 130, 'foot size': 8} training = { 'male': [{ 'height': 6, 'weight': 180, 'foot size': 12 }, { 'height': 5.92, 'weight': 190, 'foot size': 11 }, { 'height': 5.58, 'weight': 170, 'foot size': 12 }, { 'height': 5.92, 'weight': 165, 'foot size': 10 }], 'female': [{ 'height': 5, 'weight': 100, 'foot size': 6 }, { 'height': 5.5, 'weight': 150, 'foot size': 8 }, { 'height': 5.42, 'weight': 130, 'foot size': 7 }, { 'height': 5.75, 'weight': 150, 'foot size': 9 }] } self.assertEqual(classify_normal(instance, training), 'female')
classify_normal({ 'height': 6, 'weight': 130, 'foot size': 8 }, { 'male': [{ 'height': 6, 'weight': 180, 'foot size': 12 }, { 'height': 5.92, 'weight': 190, 'foot size': 11 }, { 'height': 5.58, 'weight': 170, 'foot size': 12 }, { 'height': 5.92, 'weight': 165, 'foot size': 10 }], 'female': [{ 'height': 5, 'weight': 100, 'foot size': 6 }, { 'height': 5.5, 'weight': 150, 'foot size': 8 }, { 'height': 5.42, 'weight': 130, 'foot size': 7 }, { 'height': 5.75, 'weight': 150, 'foot size': 9 }] }))
def test_basic(self): self.assertEqual(classify_normal({'a': 100, 'b': 0}, {'A': [{'a': 100, 'b': 10}, {'a': 99, 'b': -10}], 'B': [{'a': 50, 'b': 100}, {'a': 70, 'b':90}]}), 'A')
import sys sys.path.append('../') from bayesian import Bayes, classify_normal, classify print(' == High Level Functions == ') print(' -- Gender Classification -- ') # Decides if the person with those measures is male or female. print(classify_normal({'height': 6, 'weight': 130, 'foot size': 8}, {'male': [{'height': 6, 'weight': 180, 'foot size': 12}, {'height': 5.92, 'weight': 190, 'foot size': 11}, {'height': 5.58, 'weight': 170, 'foot size': 12}, {'height': 5.92, 'weight': 165, 'foot size': 10}], 'female': [{'height': 5, 'weight': 100, 'foot size': 6}, {'height': 5.5, 'weight': 150, 'foot size': 8}, {'height': 5.42, 'weight': 130, 'foot size': 7}, {'height': 5.75, 'weight': 150, 'foot size': 9}]})) print('') print(' -- Spam Detection With `Classify` -- ') spams = ["buy viagra", "dear recipient", "meet sexy singles"] # etc genuines = ["let's meet tomorrow", "remember to buy milk"] message = "remember the meeting tomorrow" # Classify as "genuine" because of the words "remember" and "tomorrow". print(classify(message, {'spam': spams, 'genuine': genuines})) # Classifies "unknown_file" as either a Python or Java file, considering # you have directories with examples of each language. #print classify_file("unknown_file", ["java_files", "python_files"])