org.apache.mahout.classifier.naivebayes
Class AbstractNaiveBayesClassifier

java.lang.Object
  extended by org.apache.mahout.classifier.AbstractVectorClassifier
      extended by org.apache.mahout.classifier.naivebayes.AbstractNaiveBayesClassifier
Direct Known Subclasses:
ComplementaryNaiveBayesClassifier, StandardNaiveBayesClassifier

public abstract class AbstractNaiveBayesClassifier
extends AbstractVectorClassifier

Class implementing the Naive Bayes Classifier Algorithm


Constructor Summary
protected AbstractNaiveBayesClassifier(NaiveBayesModel model)
           
 
Method Summary
 Vector classify(Vector instance)
          Classify a vector returning a vector of numCategories-1 scores.
 double classifyScalar(Vector instance)
          Classifies a vector in the special case of a binary classifier where AbstractVectorClassifier.classify(Vector) would return a vector with only one element.
protected  NaiveBayesModel getModel()
           
protected abstract  double getScoreForLabelFeature(int label, int feature)
           
protected  double getScoreForLabelInstance(int label, Vector instance)
           
 int numCategories()
          Returns the number of categories for the target variable.
 
Methods inherited from class org.apache.mahout.classifier.AbstractVectorClassifier
classify, classifyFull, classifyFull, classifyFull, classifyNoLink, classifyScalar, logLikelihood
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractNaiveBayesClassifier

protected AbstractNaiveBayesClassifier(NaiveBayesModel model)
Method Detail

getModel

protected NaiveBayesModel getModel()

getScoreForLabelFeature

protected abstract double getScoreForLabelFeature(int label,
                                                  int feature)

getScoreForLabelInstance

protected double getScoreForLabelInstance(int label,
                                          Vector instance)

numCategories

public int numCategories()
Description copied from class: AbstractVectorClassifier
Returns the number of categories for the target variable. A vector classifier will encode it's output using a zero-based 1 of numCategories encoding.

Specified by:
numCategories in class AbstractVectorClassifier
Returns:
The number of categories.

classify

public Vector classify(Vector instance)
Description copied from class: AbstractVectorClassifier
Classify a vector returning a vector of numCategories-1 scores. It is assumed that the score for the missing category is one minus the sum of the scores that are returned. Note that the missing score is the 0-th score.

Specified by:
classify in class AbstractVectorClassifier
Parameters:
instance - A feature vector to be classified.
Returns:
A vector of probabilities in 1 of n-1 encoding.

classifyScalar

public double classifyScalar(Vector instance)
Description copied from class: AbstractVectorClassifier
Classifies a vector in the special case of a binary classifier where AbstractVectorClassifier.classify(Vector) would return a vector with only one element. As such, using this method can void the allocation of a vector.

Specified by:
classifyScalar in class AbstractVectorClassifier
Parameters:
instance - The feature vector to be classified.
Returns:
The score for category 1.
See Also:
AbstractVectorClassifier.classify(Vector)


Copyright © 2008-2012 The Apache Software Foundation. All Rights Reserved.