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.
 Vector classifyFull(Vector instance)
          Returns n probabilities, one for each category.
 Vector classifyFull(Vector r, Vector instance)
          Returns n probabilities, one for each category into a pre-allocated vector.
 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, 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.

classifyFull

public Vector classifyFull(Vector instance)
Description copied from class: AbstractVectorClassifier
Returns n probabilities, one for each category. If you can use an n-1 coding, and are touchy about allocation performance, then the classify method is probably better to use. The 0-th element of the score vector returned by this method is the missing score as computed by the classify method.

Overrides:
classifyFull in class AbstractVectorClassifier
Parameters:
instance - A vector of features to be classified.
Returns:
A vector of probabilities, one for each category.
See Also:
AbstractVectorClassifier.classify(Vector), AbstractVectorClassifier.classifyFull(Vector r, Vector instance)

classifyFull

public Vector classifyFull(Vector r,
                           Vector instance)
Description copied from class: AbstractVectorClassifier
Returns n probabilities, one for each category into a pre-allocated vector. One vector allocation is still done in the process of multiplying by the coefficient matrix, but that is hard to avoid. The cost of such an ephemeral allocation is very small in any case compared to the multiplication itself.

Overrides:
classifyFull in class AbstractVectorClassifier
Parameters:
r - Where to put the results.
instance - A vector of features to be classified.
Returns:
A vector of probabilities, one for each category.

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)

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.


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