def testEntailmentClassifierEmptyData(self): # Arrange data, test_data, vectors = testData() vectors.nouns = defaultdict(lambda: {}) neigh = KNeighborsClassifier(n_neighbors=1) classifier = EntailmentClassifier(neigh, vectors) # Act classifier.fit(data) classifier.predict(data)
def testEntailmentClassifierEmptyData(self): # Arrange data, test_data, vectors = testData() vectors.nouns = defaultdict(lambda:{}) neigh = KNeighborsClassifier(n_neighbors=1) classifier = EntailmentClassifier(neigh, vectors) # Act classifier.fit(data) classifier.predict(data)
def runExperiment(self, classifier_name): data, test_data, vectors = testData() all_data = (data + test_data)*3 #print all_data maker = ClassifierMaker(vectors) classifier = maker.make(classifier_name) num_folds = 3 experiment = EntailmentExperiment(all_data, classifier, num_folds) results = [experiment.runFold(fold) for fold in range(num_folds)] #print results return results
def testEntailmentClassifier(self): for i in range(3): # Arrange data, test_data, vectors = testData() expected = tuple(x[2] for x in test_data) test_data = [x[:2] for x in test_data] neigh = KNeighborsClassifier(n_neighbors=1) classifier = EntailmentClassifier(neigh, vectors) # Act classifier.fit(data) results = classifier.predict(test_data) # Assert self.assertEqual(tuple(results), expected)
def testClassifierMakerClassifiers(self): "Check that all classifiers that can be made are valid." data, test_data, vectors = testData() class_values = set(x[2] for x in data) params = {'beta': [1.0, 2.0], 'costs': [1.0], 'k': [1]} maker = ClassifierMaker(vectors, params) names = maker.get_names() for name in names: classifier = maker.make(name) classifier.fit(data) results = classifier.predict(test_data) self.assertEqual(len(results), len(test_data)) self.assertTrue(set(results) <= class_values)
def testClassifierMakerClassifiers(self): "Check that all classifiers that can be made are valid." data, test_data, vectors = testData() class_values = set(x[2] for x in data) params = {'beta':[1.0, 2.0], 'costs':[1.0]} maker = ClassifierMaker(vectors, params) names = maker.get_names() for name in names: classifier = maker.make(name) classifier.fit(data) results = classifier.predict(test_data) self.assertEqual(len(results), len(test_data)) self.assertTrue(set(results) <= class_values)
def runExperiment(self, classifier_name): data, test_data, vectors = testData() all_data = (data + test_data)*3 #print all_data maker = ClassifierMaker(vectors, params = {'k':[1]} ) classifier = maker.make(classifier_name) num_folds = 3 experiment = EntailmentExperiment(all_data, classifier, num_folds) results = [experiment.runFold(fold) for fold in range(num_folds)] #print results return results
def testClassifierMakerNames(self): data, test_data, vectors = testData() maker = ClassifierMaker(vectors) names = maker.get_names() self.assertGreater(len(names), 0, "Maker should have more than one classifier")