[BioPython] Help with NaiveBayes

jchang at smi.stanford.edu jchang at smi.stanford.edu
Wed Dec 21 14:24:46 EST 2005


On Wed, Dec 21, 2005 at 10:31:47AM -0500, Sam Volchenboum wrote:
> I'm trying to get the NaiveBayes function up and running.
> 
> For the training_set, I've tried this format:
> 
> [[1, 0, 1, 1, 0, 1], [0, 0, 1, 1, 1], [0, 0, 0, 0, 0]]
> 
> which would be an example of three states and five proteins (on or off).

The first one contains data for 6 proteins.  If you make them all
lists of length 5, the training completes.

>>> from Bio import NaiveBayes
>>> training_set = [[1, 0, 1, 1, 0, 1], [0, 0, 1, 1, 1], [0, 0, 0, 0, 0]] 
>>> results = ['Healthy', 'Disease', 'Disease'] 
>>> nb = NaiveBayes.train(training_set, results)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/Users/jchang/lib/jchang/python/Bio/NaiveBayes.py", line 146, in train
    raise ValueError, "observations have different dimensionality"
ValueError: observations have different dimensionality
>>> training_set = [[1, 0, 1, 1, 0], [0, 0, 1, 1, 1], [0, 0, 0, 0, 0]]
>>> nb = NaiveBayes.train(training_set, results)
>>> NaiveBayes.classify(nb, [1, 0, 1, 1, 0])
'Healthy'
>>> NaiveBayes.classify(nb, [0, 0, 0, 1, 1])
'Disease'
>>> 

Jeff


More information about the BioPython mailing list