nltk/nltk — Issue #184: NBC most informative features method does not report features that are always present in a label and not in the other class.
Author: alexrudnick
Created: 2012-01-17 06:28:00+00:00
State: open

What version of NLTK are you using? (See nltk.__version__). Please only
submit bug reports for the current version.

2.0b8 (naivebayes.py 2063). 2063 is the present version.

What steps will reproduce the problem? (e.g. include Python source code)

import nltk
labeled_featuresets = [({'viagra': True}, 'spam'),
({'hello': True}, 'ok')]
classifier = nltk.NaiveBayesClassifier.train(labeled_featuresets)
classifier.show_most_informative_features()

This just writes "Most Informative Features"

What is the expected output? What do you see instead?

Apart from "Most Informative Features" I would expect to see 'viagra' and 'hello' listed.

Please use labels and text to provide additional information.

I seems to be an issue with the use of the .samples method line 134 and 165 in nltk/nltk/classify/naivebayes.py.

Another example is:

labeled_featuresets = [({'viagra': True, 'casino': True}, 'spam'),
({'viagra': True}, 'spam'),
({'hello': True}, 'ok')]
classifier = nltk.NaiveBayesClassifier.train(labeled_featuresets)
classifier.show_most_informative_features()

This lists only:

Most Informative Features
casino = None ok : spam = 1.5 : 1.0

Instead of

viagra = None ok : spam = 4.5 : 1.0
hello = True ok : spam = 4.5 : 1.0
hello = None spam : ok = 3.3 : 1.0
viagra = True spam : ok = 3.3 : 1.0
casino = True spam : ok = 2.0 : 1.0
casino = None ok : spam = 1.5 : 1.0

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