[frames] | no frames]

# Module NaiveBayes

source code

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:
• observation - A feature vector of discrete data.
• class - A possible classification for an observation.
Classes:
• NaiveBayes - Holds information for a naive Bayes classifier.
Functions:
• train - Train a new naive Bayes classifier.
• calculate - Calculate the probabilities of each class, given an observation.
• classify - Classify an observation into a class.
 Classes
NaiveBayes
Hold information for a NaiveBayes classifier.
 Functions

 _contents(items) Return a dictionary where the key is the item and the value is the probablity associated (PRIVATE). source code

 calculate(nb, observation, scale=False) Calculate the logarithmic conditional probability 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 NaiveBayes classifier on a training set. source code
 Variables
__package__ = `'Bio'`
 Function Details

### calculate(nb, observation, scale=False)

source code

Calculate the logarithmic conditional probability for each class.

Arguments:
• 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.

A dictionary is returned where the key is the class and the value is the log probability of the class.

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

source code

Train a NaiveBayes classifier on a training set.

Arguments:
• 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.

 Generated by Epydoc 3.0.1 on Fri Jun 22 16:34:22 2018 http://epydoc.sourceforge.net