public class NaiveBayes extends Classifier implements Serializable
To compute the likelihood:
p(Data|Classification) = p(d1,d2,..dn | Classification)
Naive Bayes makes the assumption that all of the data are conditionally
independent given the Classification:
p(d1,d2,...dn | Classification) = p(d1|Classification)p(d2|Classification)..
As with other classifiers in Mallet, NaiveBayes is implemented as two classes:
a trainer and a classifier. The NaiveBayesTrainer produces estimates of the various
p(dn|Classifier) and contructs this class with those estimates.
Instances are assumed to be FeatureVectors
As with other Mallet classifiers, classification may only be performed on instances processed with the pipe associated with this classifer, ie naiveBayes.getPipeInstance(); The NaiveBayesTrainer sets this pipe to the pipe used to process the training instances.
A NaiveBayes classifier can be persisted and reused using serialization.
NaiveBayesTrainer,
FeatureVector,
Serialized ForminstancePipe| Constructor and Description |
|---|
NaiveBayes(Pipe instancePipe,
Multinomial.Logged prior,
Multinomial.Logged[] classIndex2FeatureProb)
Construct a NaiveBayes classifier from a pipe, prior estimates for each Classification,
and feature estimates of each Classification.
|
NaiveBayes(Pipe dataPipe,
Multinomial prior,
Multinomial[] classIndex2FeatureProb)
Construct a NaiveBayes classifier from a pipe, prior estimates for each Classification,
and feature estimates of each Classification.
|
| Modifier and Type | Method and Description |
|---|---|
Classification |
classify(Instance instance)
Classify an instance using NaiveBayes according to the trained data.
|
classify, classify, classify, getAccuracy, getAccuracy, getAlphabet, getF1, getF1, getF1, getF1, getInstancePipe, getLabelAlphabet, getPrecision, getPrecision, getPrecision, getPrecision, getRecall, getRecall, getRecall, getRecall, print, printpublic NaiveBayes(Pipe instancePipe, Multinomial.Logged prior, Multinomial.Logged[] classIndex2FeatureProb)
instancePipe - Used to check that feature vector dictionary for each instance
is the same as that associated with the pipe. Null suppresses checkprior - Mulinomial that gives an estimate of the prior probability for
each ClassificationclassIndex2FeatureProb - An array of multinomials giving an estimate
of the probability of a classification for each feature of each featurevector.public NaiveBayes(Pipe dataPipe, Multinomial prior, Multinomial[] classIndex2FeatureProb)
dataPipe - Used to check that feature vector dictionary for each instance
is the same as that associated with the pipe. Null suppresses checkprior - Mulinomial that gives an estimate of the prior probability for
each ClassificationclassIndex2FeatureProb - An array of multinomials giving an estimate
of the probability of a classification for each feature of each featurevector.public Classification classify(Instance instance)
classify in class Classifierinstance - to be classified. Data field must be a FeatureVectorCopyright © 2019 JULIE Lab, Germany. All rights reserved.