All Packages  Class Hierarchy  This Package  Previous  Next  Index  WEKA's home

Class weka.classifiers.NaiveBayes

java.lang.Object
   |
   +----weka.classifiers.Classifier
           |
           +----weka.classifiers.DistributionClassifier
                   |
                   +----weka.classifiers.NaiveBayes

public class NaiveBayes
extends DistributionClassifier
implements OptionHandler, WeightedInstancesHandler
Class for a Naive Bayes classifier using estimator classes. Numeric estimator precision values are chosen based on analysis of the training data. For this reason, the classifier is not an UpdateableClassifier (which in typical usage are initialized with zero training instances) -- if you need the UpdateableClassifier functionality, Create an empty class such as the following:


 public class NaiveBayesUpdateable extends NaiveBayes 
     implements UpdateableClassifier {
 }
 
This classifier will use a default precision of 0.1 for numeric attributes when buildClassifier is called with zero training instances.

For more information on Naive Bayes classifiers, see

George H. John and Pat Langley (1995). Estimating Continuous Distributions in Bayesian Classifiers. Proceedings of the Eleventh Conference on Uncertainty in Artificial Intelligence. pp. 338-345. Morgan Kaufmann, San Mateo.

Valid options are:

-K
Use kernel estimation for modelling numeric attributes rather than a single normal distribution.

Version:
$Revision: 1.6 $
Author:
Len Trigg (trigg@cs.waikato.ac.nz), Eibe Frank (eibe@cs.waikato.ac.nz)

Constructor Index

 o NaiveBayes()

Method Index

 o buildClassifier(Instances)
Generates the classifier.
 o distributionForInstance(Instance)
Calculates the class membership probabilities for the given test instance.
 o getOptions()
Gets the current settings of the classifier.
 o getUseKernelEstimator()
Gets if kernel estimator is being used.
 o listOptions()
Returns an enumeration describing the available options
 o main(String[])
Main method for testing this class.
 o setOptions(String[])
Parses a given list of options.
 o setUseKernelEstimator(boolean)
Sets if kernel estimator is to be used.
 o toString()
Returns a description of the classifier.
 o updateClassifier(Instance)
Updates the classifier with the given instance.

Constructors

 o NaiveBayes
 public NaiveBayes()

Methods

 o buildClassifier
 public void buildClassifier(Instances instances) throws Exception
Generates the classifier.

Parameters:
instances - set of instances serving as training data
Throws: Exception
if the classifier has not been generated successfully
Overrides:
buildClassifier in class Classifier
 o updateClassifier
 public void updateClassifier(Instance instance) throws Exception
Updates the classifier with the given instance.

Parameters:
instance - the new training instance to include in the model
Throws: Exception
if the instance could not be incorporated in the model.
 o distributionForInstance
 public double[] distributionForInstance(Instance instance) throws Exception
Calculates the class membership probabilities for the given test instance.

Parameters:
instance - the instance to be classified
Returns:
predicted class probability distribution
Throws: Exception
if there is a problem generating the prediction
Overrides:
distributionForInstance in class DistributionClassifier
 o listOptions
 public Enumeration listOptions()
Returns an enumeration describing the available options

Returns:
an enumeration of all the available options
 o setOptions
 public void setOptions(String options[]) throws Exception
Parses a given list of options. Valid options are:

-K
Use kernel estimation for modelling numeric attributes rather than a single normal distribution.

Parameters:
options - the list of options as an array of strings
Throws: Exception
if an option is not supported
 o getOptions
 public String[] getOptions()
Gets the current settings of the classifier.

Returns:
an array of strings suitable for passing to setOptions
 o toString
 public String toString()
Returns a description of the classifier.

Returns:
a description of the classifier as a string.
Overrides:
toString in class Object
 o getUseKernelEstimator
 public boolean getUseKernelEstimator()
Gets if kernel estimator is being used.

Returns:
Value of m_UseKernelEstimatory.
 o setUseKernelEstimator
 public void setUseKernelEstimator(boolean v)
Sets if kernel estimator is to be used.

Parameters:
v - Value to assign to m_UseKernelEstimatory.
 o main
 public static void main(String argv[])
Main method for testing this class.

Parameters:
argv - the options

All Packages  Class Hierarchy  This Package  Previous  Next  Index  WEKA's home