nltk/nltk — Issue #155: nltk.classify.decisiontree.demo() fails on 2.0.1rc1
Author: alexrudnick
Created: 2012-01-17 06:27:19+00:00
State: open

What version of NLTK are you using? (See nltk.__version__). Please only
submit bug reports for the current version.
>>> nltk.__version__
'2.0b9'
on Mac with Python 2.7.1

What steps will reproduce the problem? (e.g. include Python source code)
Running the Decision Tree demo (nltk.classify.decisiontree.demo()) fails on 2.0.1rc1 but runs fine on 2.0b9.

What is the expected output? What do you see instead?
Below I show the correct output from nltk 2.0b9 and the error with 2.0.1rc1:

################################
Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34)
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
>>> nltk.__version__
'2.0b9'
>>> nltk.classify.decisiontree.demo()
Training classifier...
best stump for 5000 toks uses endswith(vowel)=False err=0.2556
best stump for 1802 toks uses has(y)=False err=0.3152
best stump for 1612 toks uses startswith(k)=False err=0.3033
...
if has(k) != False:
if count(m) == 2: return 'male'
if count(m) != 2: return 'female'
################################

################################
Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34)
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
>>> nltk.__version__
'2.0.1rc1'
>>> nltk.classify.decisiontree.demo()
Training classifier...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nltk/classify/decisiontree.py", line 281, in demo
binary_names_demo_features)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nltk/classify/util.py", line 182, in names_demo
classifier = trainer( [(features(n), g) for (n,g) in train] )
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nltk/classify/decisiontree.py", line 276, in f
return DecisionTreeClassifier.train(x, binary=True, verbose=True)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nltk/classify/decisiontree.py", line 156, in train
feature_names, labeled_featuresets, feature_values, verbose)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nltk/classify/decisiontree.py", line 256, in best_binary_stump
fname, fval, labeled_featuresets)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nltk/classify/decisiontree.py", line 245, in binary_stump
default = DecisionTreeClassifier(neg_fdist.max())
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nltk/probability.py", line 283, in max
self._max_cache = max([(a,b) for (b,a) in self.items()])[1]
ValueError: max() arg is an empty sequence
################################

Please use labels and text to provide additional information.
I haven't debugged this issue, I upgraded from 2.0b9 to 2.0.1rc1 this morning. I have already filed http://code.google.com/p/nltk/issues/detail?id=667 but I don't think these are related.

Migrated from http://code.google.com/p/nltk/issues/detail?id=668