示例#1
0
    def test_names_nltk(self):
        """Classify names using NLTK features"""
        train, dev, test = self.split_names_corpus()
        classifier = MaxEnt()
        classifier.labels = ['female', 'male']
        classifier.vocab = self.get_names_vocab(train)
        classifier.feature_vectors(train + dev + test)
        classifier.train(train, dev)

        acc = accuracy(classifier, test)
        self.assertGreater(acc, 0.70)
示例#2
0
    def test_reviews_bag(self):
        """Classify sentiment using bag-of-words"""
        train, dev, test = self.split_review_corpus(BagOfWords)
        classifier = MaxEnt()
        classifier.labels = ['positive', 'negative', 'neutral']
        classifier.vocab = self.get_review_vocab(train)
        print('...creating sparse feature vectors...')
        classifier.feature_vectors(train + dev + test)

        print('...training...')
        classifier.train(train, dev)
        self.assertGreater(accuracy(classifier, test), 0.55)