Commit 679680d3 by Steven Bird

Merge pull request #642 from jskda/pull_request.unit_test_fixes

Pull request.unit test fixes
parents 7cc64b2f ef4c50b0
...@@ -53,7 +53,7 @@ of ``None``. ...@@ -53,7 +53,7 @@ of ``None``.
We evaluate a tagger on data that was not seen during training: We evaluate a tagger on data that was not seen during training:
>>> tagger.evaluate(brown.tagged_sents(categories='news')[500:600]) >>> tagger.evaluate(brown.tagged_sents(categories='news')[500:600])
0.734... 0.73...
For more information, please consult chapter 5 of the NLTK Book. For more information, please consult chapter 5 of the NLTK Book.
""" """
......
...@@ -13,11 +13,11 @@ implement the `ClassifyI` interface: ...@@ -13,11 +13,11 @@ implement the `ClassifyI` interface:
>>> import nltk >>> import nltk
>>> nltk.usage(nltk.classify.ClassifierI) >>> nltk.usage(nltk.classify.ClassifierI)
ClassifierI supports the following operations: ClassifierI supports the following operations:
- self.batch_classify(featuresets)
- self.batch_prob_classify(featuresets)
- self.classify(featureset) - self.classify(featureset)
- self.classify_many(featuresets)
- self.labels() - self.labels()
- self.prob_classify(featureset) - self.prob_classify(featureset)
- self.prob_classify_many(featuresets)
NLTK defines several classifier classes: NLTK defines several classifier classes:
...@@ -62,9 +62,9 @@ Test the Naive Bayes classifier: ...@@ -62,9 +62,9 @@ Test the Naive Bayes classifier:
>>> classifier = nltk.classify.NaiveBayesClassifier.train(train) >>> classifier = nltk.classify.NaiveBayesClassifier.train(train)
>>> sorted(classifier.labels()) >>> sorted(classifier.labels())
['x', 'y'] ['x', 'y']
>>> classifier.batch_classify(test) >>> classifier.classify_many(test)
['y', 'x', 'y', 'x'] ['y', 'x', 'y', 'x']
>>> for pdist in classifier.batch_prob_classify(test): >>> for pdist in classifier.prob_classify_many(test):
... print('%.4f %.4f' % (pdist.prob('x'), pdist.prob('y'))) ... print('%.4f %.4f' % (pdist.prob('x'), pdist.prob('y')))
0.3104 0.6896 0.3104 0.6896
0.5746 0.4254 0.5746 0.4254
...@@ -92,9 +92,9 @@ Test the Decision Tree classifier: ...@@ -92,9 +92,9 @@ Test the Decision Tree classifier:
a=1? ................................................ y a=1? ................................................ y
c=1? .................................................. y c=1? .................................................. y
<BLANKLINE> <BLANKLINE>
>>> classifier.batch_classify(test) >>> classifier.classify_many(test)
['y', 'y', 'y', 'x'] ['y', 'y', 'y', 'x']
>>> for pdist in classifier.batch_prob_classify(test): >>> for pdist in classifier.prob_classify_many(test):
... print('%.4f %.4f' % (pdist.prob('x'), pdist.prob('y'))) ... print('%.4f %.4f' % (pdist.prob('x'), pdist.prob('y')))
Traceback (most recent call last): Traceback (most recent call last):
. . . . . .
...@@ -113,10 +113,10 @@ Test SklearnClassifier, which requires the scikit-learn package. ...@@ -113,10 +113,10 @@ Test SklearnClassifier, which requires the scikit-learn package.
>>> classif = SklearnClassifier(BernoulliNB()).train(train_data) >>> classif = SklearnClassifier(BernoulliNB()).train(train_data)
>>> test_data = [{"a": 3, "b": 2, "c": 1}, >>> test_data = [{"a": 3, "b": 2, "c": 1},
... {"a": 0, "b": 3, "c": 7}] ... {"a": 0, "b": 3, "c": 7}]
>>> classif.batch_classify(test_data) >>> classif.classify_many(test_data)
['ham', 'spam'] ['ham', 'spam']
>>> classif = SklearnClassifier(SVC(), sparse=False).train(train_data) >>> classif = SklearnClassifier(SVC(), sparse=False).train(train_data)
>>> classif.batch_classify(test_data) >>> classif.classify_many(test_data)
['ham', 'spam'] ['ham', 'spam']
Test the Maximum Entropy classifier training algorithms; they should all Test the Maximum Entropy classifier training algorithms; they should all
...@@ -179,7 +179,7 @@ Regression tests for TypedMaxentFeatureEncoding ...@@ -179,7 +179,7 @@ Regression tests for TypedMaxentFeatureEncoding
>>> classifier = maxent.MaxentClassifier.train( >>> classifier = maxent.MaxentClassifier.train(
... train, bernoulli=False, encoding=encoding, trace=0) ... train, bernoulli=False, encoding=encoding, trace=0)
>>> classifier.batch_classify(test) >>> classifier.classify_many(test)
['y', 'x'] ['y', 'x']
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment