MOA 12.03
Real Time Analytics for Data Streams
|
Class for building and using a multinomial Naive Bayes classifier. More...
Public Member Functions | |
String | getPurposeString () |
Gets the purpose of this object. | |
void | resetLearningImpl () |
Resets this classifier. | |
void | trainOnInstanceImpl (Instance inst) |
Trains the classifier with the given instance. | |
double[] | getVotesForInstance (Instance instance) |
Calculates the class membership probabilities for the given test instance. | |
double | totalSize (Instance instance) |
void | getModelDescription (StringBuilder result, int indent) |
Returns a string representation of the model. | |
boolean | isRandomizable () |
Gets whether this classifier needs a random seed. | |
Public Attributes | |
FloatOption | laplaceCorrectionOption |
Protected Member Functions | |
Measurement[] | getModelMeasurementsImpl () |
Gets the current measurements of this classifier. | |
Protected Attributes | |
double[] | m_classTotals |
sum of weight_of_instance * word_count_of_instance for each class | |
Instances | m_headerInfo |
copy of header information for use in toString method | |
int | m_numClasses |
number of class values | |
double[] | m_probOfClass |
the probability of a class (i.e. | |
double[][] | m_wordTotalForClass |
probability that a word (w) exists in a class (H) (i.e. | |
boolean | reset = false |
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} }
Definition at line 54 of file NaiveBayesMultinomial.java.
void moa.classifiers.bayes.NaiveBayesMultinomial.getModelDescription | ( | StringBuilder | out, |
int | indent | ||
) | [virtual] |
Returns a string representation of the model.
out | the stringbuilder to add the description |
indent | the number of characters to indent |
Implements moa.classifiers.AbstractClassifier.
Definition at line 205 of file NaiveBayesMultinomial.java.
Measurement [] moa.classifiers.bayes.NaiveBayesMultinomial.getModelMeasurementsImpl | ( | ) | [protected, virtual] |
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.
Implements moa.classifiers.AbstractClassifier.
Definition at line 200 of file NaiveBayesMultinomial.java.
String moa.classifiers.bayes.NaiveBayesMultinomial.getPurposeString | ( | ) |
Gets the purpose of this object.
Reimplemented from moa.classifiers.AbstractClassifier.
Definition at line 66 of file NaiveBayesMultinomial.java.
double [] moa.classifiers.bayes.NaiveBayesMultinomial.getVotesForInstance | ( | Instance | instance | ) |
Calculates the class membership probabilities for the given test instance.
instance | the instance to be classified |
Implements moa.classifiers.Classifier.
Definition at line 153 of file NaiveBayesMultinomial.java.
boolean moa.classifiers.bayes.NaiveBayesMultinomial.isRandomizable | ( | ) |
Gets whether this classifier needs a random seed.
Examples of methods that needs a random seed are bagging and boosting.
Implements moa.classifiers.Classifier.
Definition at line 239 of file NaiveBayesMultinomial.java.
void moa.classifiers.bayes.NaiveBayesMultinomial.resetLearningImpl | ( | ) | [virtual] |
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.
Implements moa.classifiers.AbstractClassifier.
Definition at line 99 of file NaiveBayesMultinomial.java.
double moa.classifiers.bayes.NaiveBayesMultinomial.totalSize | ( | Instance | instance | ) |
Definition at line 180 of file NaiveBayesMultinomial.java.
Referenced by moa.classifiers.bayes.NaiveBayesMultinomial.getVotesForInstance(), and moa.classifiers.bayes.NaiveBayesMultinomial.trainOnInstanceImpl().
void moa.classifiers.bayes.NaiveBayesMultinomial.trainOnInstanceImpl | ( | Instance | inst | ) | [virtual] |
Trains the classifier with the given instance.
instance | the new training instance to include in the model |
Implements moa.classifiers.AbstractClassifier.
Definition at line 109 of file NaiveBayesMultinomial.java.
new FloatOption("laplaceCorrection", 'l', "Laplace correction factor.", 1.0, 0.00, Integer.MAX_VALUE)
Definition at line 56 of file NaiveBayesMultinomial.java.
Referenced by moa.classifiers.bayes.NaiveBayesMultinomial.trainOnInstanceImpl().
double [] moa.classifiers.bayes.NaiveBayesMultinomial.m_classTotals [protected] |
sum of weight_of_instance * word_count_of_instance for each class
Definition at line 73 of file NaiveBayesMultinomial.java.
Referenced by moa.classifiers.bayes.NaiveBayesMultinomial.getModelDescription(), moa.classifiers.bayes.NaiveBayesMultinomial.getVotesForInstance(), and moa.classifiers.bayes.NaiveBayesMultinomial.trainOnInstanceImpl().
Instances moa.classifiers.bayes.NaiveBayesMultinomial.m_headerInfo [protected] |
copy of header information for use in toString method
Definition at line 78 of file NaiveBayesMultinomial.java.
Referenced by moa.classifiers.bayes.NaiveBayesMultinomial.getModelDescription().
int moa.classifiers.bayes.NaiveBayesMultinomial.m_numClasses [protected] |
number of class values
Definition at line 83 of file NaiveBayesMultinomial.java.
Referenced by moa.classifiers.bayes.NaiveBayesMultinomial.getModelDescription(), moa.classifiers.bayes.NaiveBayesMultinomial.getVotesForInstance(), and moa.classifiers.bayes.NaiveBayesMultinomial.trainOnInstanceImpl().
double [] moa.classifiers.bayes.NaiveBayesMultinomial.m_probOfClass [protected] |
the probability of a class (i.e.
Pr[H])
Definition at line 88 of file NaiveBayesMultinomial.java.
Referenced by moa.classifiers.bayes.NaiveBayesMultinomial.getModelDescription(), moa.classifiers.bayes.NaiveBayesMultinomial.getVotesForInstance(), and moa.classifiers.bayes.NaiveBayesMultinomial.trainOnInstanceImpl().
double [][] moa.classifiers.bayes.NaiveBayesMultinomial.m_wordTotalForClass [protected] |
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]
Definition at line 94 of file NaiveBayesMultinomial.java.
Referenced by moa.classifiers.bayes.NaiveBayesMultinomial.getModelDescription(), moa.classifiers.bayes.NaiveBayesMultinomial.getVotesForInstance(), and moa.classifiers.bayes.NaiveBayesMultinomial.trainOnInstanceImpl().
boolean moa.classifiers.bayes.NaiveBayesMultinomial.reset = false [protected] |