Package Bio :: Module NaiveBayes
[hide private]
[frames] | no frames]

Module NaiveBayes

source code

This provides code for a general Naive Bayes learner.

Naive Bayes is a supervised classification algorithm that uses Bayes rule to compute the fit between a new observation and some previously observed data. The observations are discrete feature vectors, with the Bayes assumption that the features are independent. Although this is hardly ever true, the classifier works well enough in practice.

Glossary:
Classes:
Functions:
Classes [hide private]
  NaiveBayes
Holds information for a NaiveBayes classifier.
Functions [hide private]
 
_contents(items) source code
 
calculate(nb, observation, scale=False)
Calculate log P(class|observation) for each class.
source code
 
classify(nb, observation)
Classify an observation into a class.
source code
 
train(training_set, results, priors=None, typecode=None)
Train a naive bayes classifier on a training set.
source code
Variables [hide private]
  __package__ = 'Bio'
Function Details [hide private]

calculate(nb, observation, scale=False)

source code 

Calculate log P(class|observation) for each class.

  • nb - A NaiveBayes classifier that has been trained.
  • observation - A list representing the observed data.
  • scale - Boolean to indicate whether the probability should be scaled by P(observation). By default, no scaling is done.
Returns:
A dictionary where the keys is the class and the value is the log probability of the class.

classify(nb, observation)

source code 

Classify an observation into a class.

classify(nb, observation) -> class

train(training_set, results, priors=None, typecode=None)

source code 

Train a naive bayes classifier on a training set.

train(training_set, results[, priors]) -> NaiveBayes

  • training_set - List of observations.
  • results - List of the class assignments for each observation. Thus, training_set and results must be the same length.
  • priors - Optional dictionary specifying the prior probabilities for each type of result. If not specified, the priors will be estimated from the training results.