Exemple #1
0
 def test_three_classes_no_tie(self):
     training_set = DataSet([[1, 0.5], [1, 2], [1, 3], [2, 0.5], [2, 2.5], 
                             [2, 3], [2.5, 1.5], [3, 1]], 
                            labels=["a", "a", "a", "a", "b", "a", "c", "a"])
     classifier = Knn(training_set, k=5)
     result = classifier.classify([2, 1.5])
     self.assertEqual(result, "a")
Exemple #2
0
 def test_k_greater_than_num_samples(self):
     training_set = DataSet([[1, 1], [1, 3], [3, 2]], 
                            labels=["a", "a", "b"])
     classifier = Knn(training_set, k=7)
     result = classifier.classify([2, 2])
     self.assertEqual(result, "a")
Exemple #3
0
 def test_tie(self):
     training_set = DataSet([[1, 7], [1.5, 6.5], [1.5, 8], [2.5, 6.5], 
                             [2.5, 8]], labels=["c", "b", "a", "b", "a"])
     classifier = Knn(training_set, k=5)
     result = classifier.classify([2, 7])
     self.assertEqual(result, "b")
Exemple #4
0
 def test_two_classes_no_tie(self):
     training_set = DataSet([[8, 4], [8, 5], [8, 6], [9, 4], [9, 6]], 
                            labels=["b", "c", "c", "b", "c"])
     classifier = Knn(training_set, k=5)
     result = classifier.classify([9, 5])
     self.assertEqual(result, "c")