Package moa.classifiers.bayes
Class NaiveBayesMultinomial
- java.lang.Object
-
- moa.AbstractMOAObject
-
- moa.options.AbstractOptionHandler
-
- moa.classifiers.AbstractClassifier
-
- moa.classifiers.bayes.NaiveBayesMultinomial
-
- All Implemented Interfaces:
Configurable
,Serializable
,CapabilitiesHandler
,Classifier
,MultiClassClassifier
,AWTRenderable
,Learner<Example<Instance>>
,MOAObject
,OptionHandler
public class NaiveBayesMultinomial extends AbstractClassifier implements MultiClassClassifier
Class for building and using a multinomial Naive Bayes classifier. Performs text classic bayesian prediction while making naive assumption that all inputs are independent. For more information see,
Andrew Mccallum, Kamal Nigam: A Comparison of Event Models for Naive Bayes Text Classification. In: AAAI-98 Workshop on 'Learning for Text Categorization', 1998.
The core equation for this classifier:
P[Ci|D] = (P[D|Ci] x P[Ci]) / P[D] (Bayes rule)
where Ci is class i and D is a document.
Incremental version of the algorithm. * BibTeX:@inproceedings{Mccallum1998, author = {Andrew Mccallum and Kamal Nigam}, booktitle = {AAAI-98 Workshop on 'Learning for Text Categorization'}, title = {A Comparison of Event Models for Naive Bayes Text Classification}, year = {1998} }
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description FloatOption
laplaceCorrectionOption
protected double[]
m_classTotals
sum of weight_of_instance * word_count_of_instance for each classprotected Instances
m_headerInfo
copy of header information for use in toString methodprotected int
m_numClasses
number of class valuesprotected double[]
m_probOfClass
the probability of a class (i.e.protected DoubleVector[]
m_wordTotalForClass
probability that a word (w) exists in a class (H) (i.e.protected boolean
reset
-
Fields inherited from class moa.classifiers.AbstractClassifier
classifierRandom, modelContext, randomSeed, randomSeedOption, trainingWeightSeenByModel
-
Fields inherited from class moa.options.AbstractOptionHandler
config
-
-
Constructor Summary
Constructors Constructor Description NaiveBayesMultinomial()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ImmutableCapabilities
defineImmutableCapabilities()
Defines the set of capabilities the object has.void
getModelDescription(StringBuilder result, int indent)
Returns a string representation of the model.protected Measurement[]
getModelMeasurementsImpl()
Gets the current measurements of this classifier.
The reason for ...Impl methods: ease programmer burden by not requiring them to remember calls to super in overridden methods.String
getPurposeString()
Dictionary with option texts and objectsdouble[]
getVotesForInstance(Instance instance)
Calculates the class membership probabilities for the given test instance.boolean
isRandomizable()
Gets whether this learner needs a random seed.void
resetLearningImpl()
Resets this classifier.double
totalSize(Instance instance)
void
trainOnInstanceImpl(Instance inst)
Trains the classifier with the given instance.-
Methods inherited from class moa.classifiers.AbstractClassifier
contextIsCompatible, copy, correctlyClassifies, getAttributeNameString, getAWTRenderer, getClassLabelString, getClassNameString, getDescription, getModel, getModelContext, getModelMeasurements, getNominalValueString, getPredictionForInstance, getPredictionForInstance, getSubClassifiers, getSublearners, getVotesForInstance, modelAttIndexToInstanceAttIndex, modelAttIndexToInstanceAttIndex, prepareForUseImpl, resetLearning, setModelContext, setRandomSeed, trainingHasStarted, trainingWeightSeenByModel, trainOnInstance, trainOnInstance
-
Methods inherited from class moa.options.AbstractOptionHandler
getCLICreationString, getOptions, getPreparedClassOption, prepareClassOptions, prepareForUse, prepareForUse
-
Methods inherited from class moa.AbstractMOAObject
copy, measureByteSize, measureByteSize, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface moa.capabilities.CapabilitiesHandler
getCapabilities
-
Methods inherited from interface moa.MOAObject
measureByteSize
-
Methods inherited from interface moa.options.OptionHandler
getCLICreationString, getOptions, prepareForUse, prepareForUse
-
-
-
-
Field Detail
-
laplaceCorrectionOption
public FloatOption laplaceCorrectionOption
-
m_classTotals
protected double[] m_classTotals
sum of weight_of_instance * word_count_of_instance for each class
-
m_headerInfo
protected Instances m_headerInfo
copy of header information for use in toString method
-
m_numClasses
protected int m_numClasses
number of class values
-
m_probOfClass
protected double[] m_probOfClass
the probability of a class (i.e. Pr[H])
-
m_wordTotalForClass
protected DoubleVector[] m_wordTotalForClass
probability that a word (w) exists in a class (H) (i.e. Pr[w|H]) The matrix is in the this format: m_wordTotalForClass[wordAttribute][class]
-
reset
protected boolean reset
-
-
Method Detail
-
getPurposeString
public String getPurposeString()
Description copied from class:AbstractOptionHandler
Dictionary with option texts and objects- Specified by:
getPurposeString
in interfaceOptionHandler
- Overrides:
getPurposeString
in classAbstractClassifier
- Returns:
- the string with the purpose of this object
-
resetLearningImpl
public void resetLearningImpl()
Description copied from class:AbstractClassifier
Resets this classifier. It must be similar to starting a new classifier from scratch.
The reason for ...Impl methods: ease programmer burden by not requiring them to remember calls to super in overridden methods. Note that this will produce compiler errors if not overridden.- Specified by:
resetLearningImpl
in classAbstractClassifier
-
trainOnInstanceImpl
public void trainOnInstanceImpl(Instance inst)
Trains the classifier with the given instance.- Specified by:
trainOnInstanceImpl
in classAbstractClassifier
- Parameters:
inst
- the new training instance to include in the model
-
getVotesForInstance
public double[] getVotesForInstance(Instance instance)
Calculates the class membership probabilities for the given test instance.- Specified by:
getVotesForInstance
in interfaceClassifier
- Specified by:
getVotesForInstance
in classAbstractClassifier
- Parameters:
instance
- the instance to be classified- Returns:
- predicted class probability distribution
-
totalSize
public double totalSize(Instance instance)
-
getModelMeasurementsImpl
protected Measurement[] getModelMeasurementsImpl()
Description copied from class:AbstractClassifier
Gets the current measurements of this classifier.
The reason for ...Impl methods: ease programmer burden by not requiring them to remember calls to super in overridden methods. Note that this will produce compiler errors if not overridden.- Specified by:
getModelMeasurementsImpl
in classAbstractClassifier
- Returns:
- an array of measurements to be used in evaluation tasks
-
getModelDescription
public void getModelDescription(StringBuilder result, int indent)
Description copied from class:AbstractClassifier
Returns a string representation of the model.- Specified by:
getModelDescription
in classAbstractClassifier
- Parameters:
result
- the stringbuilder to add the descriptionindent
- the number of characters to indent
-
isRandomizable
public boolean isRandomizable()
Description copied from interface:Learner
Gets whether this learner needs a random seed. Examples of methods that needs a random seed are bagging and boosting.- Specified by:
isRandomizable
in interfaceLearner<Example<Instance>>
- Returns:
- true if the learner needs a random seed.
-
defineImmutableCapabilities
public ImmutableCapabilities defineImmutableCapabilities()
Description copied from interface:CapabilitiesHandler
Defines the set of capabilities the object has. Should be overridden if the object's capabilities do not change.- Specified by:
defineImmutableCapabilities
in interfaceCapabilitiesHandler
- Overrides:
defineImmutableCapabilities
in classAbstractClassifier
- Returns:
- The capabilities of the object.
-
-