Package weka.classifiers.bayes
Class NaiveBayes
- java.lang.Object
-
- weka.classifiers.AbstractClassifier
-
- weka.classifiers.bayes.NaiveBayes
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,Classifier,Aggregateable<NaiveBayes>,BatchPredictor,CapabilitiesHandler,CapabilitiesIgnorer,CommandlineRunnable,OptionHandler,RevisionHandler,TechnicalInformationHandler,WeightedAttributesHandler,WeightedInstancesHandler
- Direct Known Subclasses:
NaiveBayesUpdateable
public class NaiveBayes extends AbstractClassifier implements OptionHandler, WeightedInstancesHandler, WeightedAttributesHandler, TechnicalInformationHandler, Aggregateable<NaiveBayes>
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, use the NaiveBayesUpdateable classifier. The NaiveBayesUpdateable 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, Pat Langley: Estimating Continuous Distributions in Bayesian Classifiers. In: Eleventh Conference on Uncertainty in Artificial Intelligence, San Mateo, 338-345, 1995. BibTeX:@inproceedings{John1995, address = {San Mateo}, author = {George H. John and Pat Langley}, booktitle = {Eleventh Conference on Uncertainty in Artificial Intelligence}, pages = {338-345}, publisher = {Morgan Kaufmann}, title = {Estimating Continuous Distributions in Bayesian Classifiers}, year = {1995} }Valid options are:-K Use kernel density estimator rather than normal distribution for numeric attributes
-D Use supervised discretization to process numeric attributes
-O Display model in old format (good when there are many classes)
- Version:
- $Revision: 15233 $
- Author:
- Len Trigg (trigg@cs.waikato.ac.nz), Eibe Frank (eibe@cs.waikato.ac.nz)
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class weka.classifiers.AbstractClassifier
BATCH_SIZE_DEFAULT, NUM_DECIMAL_PLACES_DEFAULT
-
-
Constructor Summary
Constructors Constructor Description NaiveBayes()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description NaiveBayesaggregate(NaiveBayes toAggregate)Aggregate an object with this onevoidbuildClassifier(Instances instances)Generates the classifier.java.lang.StringdisplayModelInOldFormatTipText()Returns the tip text for this propertydouble[]distributionForInstance(Instance instance)Calculates the class membership probabilities for the given test instance.voidfinalizeAggregation()Call to complete the aggregation process.CapabilitiesgetCapabilities()Returns default capabilities of the classifier.EstimatorgetClassEstimator()Get the class estimator.Estimator[][]getConditionalEstimators()Get all the conditional estimators.booleangetDisplayModelInOldFormat()Get whether to display model output in the old, original format.InstancesgetHeader()Return the header that this classifier was trained withjava.lang.String[]getOptions()Gets the current settings of the classifier.java.lang.StringgetRevision()Returns the revision string.TechnicalInformationgetTechnicalInformation()Returns an instance of a TechnicalInformation object, containing detailed information about the technical background of this class, e.g., paper reference or book this class is based on.booleangetUseKernelEstimator()Gets if kernel estimator is being used.booleangetUseSupervisedDiscretization()Get whether supervised discretization is to be used.java.lang.StringglobalInfo()Returns a string describing this classifierjava.util.Enumeration<Option>listOptions()Returns an enumeration describing the available options.static voidmain(java.lang.String[] argv)Main method for testing this class.voidsetDisplayModelInOldFormat(boolean d)Set whether to display model output in the old, original format.voidsetOptions(java.lang.String[] options)Parses a given list of options.voidsetUseKernelEstimator(boolean v)Sets if kernel estimator is to be used.voidsetUseSupervisedDiscretization(boolean s)Set whether supervised discretization is to be used.java.lang.StringtoString()Returns a description of the classifier.voidupdateClassifier(Instance instance)Updates the classifier with the given instance.java.lang.StringuseKernelEstimatorTipText()Returns the tip text for this propertyjava.lang.StringuseSupervisedDiscretizationTipText()Returns the tip text for this property-
Methods inherited from class weka.classifiers.AbstractClassifier
batchSizeTipText, classifyInstance, debugTipText, distributionsForInstances, doNotCheckCapabilitiesTipText, forName, getBatchSize, getDebug, getDoNotCheckCapabilities, getNumDecimalPlaces, implementsMoreEfficientBatchPrediction, makeCopies, makeCopy, numDecimalPlacesTipText, postExecution, preExecution, run, runClassifier, setBatchSize, setDebug, setDoNotCheckCapabilities, setNumDecimalPlaces
-
-
-
-
Method Detail
-
globalInfo
public java.lang.String globalInfo()
Returns a string describing this classifier- Returns:
- a description of the classifier suitable for displaying in the explorer/experimenter gui
-
getTechnicalInformation
public TechnicalInformation getTechnicalInformation()
Returns an instance of a TechnicalInformation object, containing detailed information about the technical background of this class, e.g., paper reference or book this class is based on.- Specified by:
getTechnicalInformationin interfaceTechnicalInformationHandler- Returns:
- the technical information about this class
-
getCapabilities
public Capabilities getCapabilities()
Returns default capabilities of the classifier.- Specified by:
getCapabilitiesin interfaceCapabilitiesHandler- Specified by:
getCapabilitiesin interfaceClassifier- Overrides:
getCapabilitiesin classAbstractClassifier- Returns:
- the capabilities of this classifier
- See Also:
Capabilities
-
buildClassifier
public void buildClassifier(Instances instances) throws java.lang.Exception
Generates the classifier.- Specified by:
buildClassifierin interfaceClassifier- Parameters:
instances- set of instances serving as training data- Throws:
java.lang.Exception- if the classifier has not been generated successfully
-
updateClassifier
public void updateClassifier(Instance instance) throws java.lang.Exception
Updates the classifier with the given instance.- Parameters:
instance- the new training instance to include in the model- Throws:
java.lang.Exception- if the instance could not be incorporated in the model.
-
distributionForInstance
public double[] distributionForInstance(Instance instance) throws java.lang.Exception
Calculates the class membership probabilities for the given test instance.- Specified by:
distributionForInstancein interfaceClassifier- Overrides:
distributionForInstancein classAbstractClassifier- Parameters:
instance- the instance to be classified- Returns:
- predicted class probability distribution
- Throws:
java.lang.Exception- if there is a problem generating the prediction
-
listOptions
public java.util.Enumeration<Option> listOptions()
Returns an enumeration describing the available options.- Specified by:
listOptionsin interfaceOptionHandler- Overrides:
listOptionsin classAbstractClassifier- Returns:
- an enumeration of all the available options.
-
setOptions
public void setOptions(java.lang.String[] options) throws java.lang.ExceptionParses a given list of options. Valid options are:-K Use kernel density estimator rather than normal distribution for numeric attributes
-D Use supervised discretization to process numeric attributes
-O Display model in old format (good when there are many classes)
- Specified by:
setOptionsin interfaceOptionHandler- Overrides:
setOptionsin classAbstractClassifier- Parameters:
options- the list of options as an array of strings- Throws:
java.lang.Exception- if an option is not supported
-
getOptions
public java.lang.String[] getOptions()
Gets the current settings of the classifier.- Specified by:
getOptionsin interfaceOptionHandler- Overrides:
getOptionsin classAbstractClassifier- Returns:
- an array of strings suitable for passing to setOptions
-
toString
public java.lang.String toString()
Returns a description of the classifier.- Overrides:
toStringin classjava.lang.Object- Returns:
- a description of the classifier as a string.
-
useKernelEstimatorTipText
public java.lang.String useKernelEstimatorTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getUseKernelEstimator
public boolean getUseKernelEstimator()
Gets if kernel estimator is being used.- Returns:
- Value of m_UseKernelEstimatory.
-
setUseKernelEstimator
public void setUseKernelEstimator(boolean v)
Sets if kernel estimator is to be used.- Parameters:
v- Value to assign to m_UseKernelEstimatory.
-
useSupervisedDiscretizationTipText
public java.lang.String useSupervisedDiscretizationTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getUseSupervisedDiscretization
public boolean getUseSupervisedDiscretization()
Get whether supervised discretization is to be used.- Returns:
- true if supervised discretization is to be used.
-
setUseSupervisedDiscretization
public void setUseSupervisedDiscretization(boolean s)
Set whether supervised discretization is to be used.- Parameters:
s- true if supervised discretization is to be used.
-
displayModelInOldFormatTipText
public java.lang.String displayModelInOldFormatTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setDisplayModelInOldFormat
public void setDisplayModelInOldFormat(boolean d)
Set whether to display model output in the old, original format.- Parameters:
d- true if model ouput is to be shown in the old format
-
getDisplayModelInOldFormat
public boolean getDisplayModelInOldFormat()
Get whether to display model output in the old, original format.- Returns:
- true if model ouput is to be shown in the old format
-
getHeader
public Instances getHeader()
Return the header that this classifier was trained with- Returns:
- the header that this classifier was trained with
-
getConditionalEstimators
public Estimator[][] getConditionalEstimators()
Get all the conditional estimators.- Returns:
- all the conditional estimators.
-
getClassEstimator
public Estimator getClassEstimator()
Get the class estimator.- Returns:
- the class estimator
-
getRevision
public java.lang.String getRevision()
Returns the revision string.- Specified by:
getRevisionin interfaceRevisionHandler- Overrides:
getRevisionin classAbstractClassifier- Returns:
- the revision
-
aggregate
public NaiveBayes aggregate(NaiveBayes toAggregate) throws java.lang.Exception
Description copied from interface:AggregateableAggregate an object with this one- Specified by:
aggregatein interfaceAggregateable<NaiveBayes>- Parameters:
toAggregate- the object to aggregate- Returns:
- the result of aggregation
- Throws:
java.lang.Exception- if the supplied object can't be aggregated for some reason
-
finalizeAggregation
public void finalizeAggregation() throws java.lang.ExceptionDescription copied from interface:AggregateableCall to complete the aggregation process. Allows implementers to do any final processing based on how many objects were aggregated.- Specified by:
finalizeAggregationin interfaceAggregateable<NaiveBayes>- Throws:
java.lang.Exception- if the aggregation can't be finalized for some reason
-
main
public static void main(java.lang.String[] argv)
Main method for testing this class.- Parameters:
argv- the options
-
-