public abstract class AbstractNaiveBayesClassifier extends AbstractVectorClassifier
classifyFull(org.apache.mahout.math.Vector)
, but not classify
or
classifyScalar
. The reason that these two methods are not
supported is because the scores computed by a NaiveBayesClassifier do not
represent probabilities.MIN_LOG_LIKELIHOOD
Modifier | Constructor and Description |
---|---|
protected |
AbstractNaiveBayesClassifier(NaiveBayesModel model) |
Modifier and Type | Method and Description |
---|---|
Vector |
classify(Vector instance)
Unsupported method.
|
Vector |
classifyFull(Vector instance)
Computes and returns a vector containing
n scores, where
n is numCategories() , given an input vector
instance . |
Vector |
classifyFull(Vector r,
Vector instance)
Computes and returns a vector containing
n scores, where
n is numCategories() , given an input vector
instance . |
double |
classifyScalar(Vector instance)
Unsupported method.
|
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 that a target variable can be assigned to.
|
classify, classifyFull, classifyNoLink, classifyScalar, logLikelihood
protected AbstractNaiveBayesClassifier(NaiveBayesModel model)
protected NaiveBayesModel getModel()
protected abstract double getScoreForLabelFeature(int label, int feature)
protected double getScoreForLabelInstance(int label, Vector instance)
public int numCategories()
AbstractVectorClassifier
0
to numCategories()-1
(inclusive).numCategories
in class AbstractVectorClassifier
public Vector classifyFull(Vector instance)
AbstractVectorClassifier
n
scores, where
n
is numCategories()
, given an input vector
instance
. Higher scores indicate that the input vector is more
likely to belong to the corresponding category. The categories are denoted
by the integers 0
through n-1
(inclusive).
Using this method it is possible to classify an input vector, for example,
by selecting the category with the largest score. If
classifier
is an instance of
AbstractVectorClassifier
and input
is a
Vector
of features describing an element to be classified,
then the following code could be used to classify input
.
Vector scores = classifier.classifyFull(input);<br>
int assignedCategory = scores.maxValueIndex();<br>
Here assignedCategory
is the index of the category
with the maximum score.
If an n-1
encoding is acceptable, and allocation performance
is an issue, then the AbstractVectorClassifier.classify(Vector)
method is probably better
to use.
classifyFull
in class AbstractVectorClassifier
instance
- A vector of features to be classified.AbstractVectorClassifier.classify(Vector)
,
AbstractVectorClassifier.classifyFull(Vector r, Vector instance)
public Vector classifyFull(Vector r, Vector instance)
AbstractVectorClassifier
n
scores, where
n
is numCategories()
, given an input vector
instance
. Higher scores indicate that the input vector is more
likely to belong to the corresponding category. The categories are denoted
by the integers 0
through n-1
(inclusive). The
main difference between this method and AbstractVectorClassifier.classifyFull(Vector)
is
that this method allows a user to provide a previously allocated
Vector r
to store the returned scores.
Using this method it is possible to classify an input vector, for example,
by selecting the category with the largest score. If
classifier
is an instance of
AbstractVectorClassifier
, result
is a non-null
Vector
, and input
is a Vector
of
features describing an element to be classified, then the following code
could be used to classify input
.
Vector scores = classifier.classifyFull(result, input); // Notice that scores == result<br>
int assignedCategory = scores.maxValueIndex();<br>
Here assignedCategory
is the index of the category
with the maximum score.
classifyFull
in class AbstractVectorClassifier
r
- Where to put the results.instance
- A vector of features to be classified.public double classifyScalar(Vector instance)
UnsupportedOperationException
.classifyScalar
in class AbstractVectorClassifier
instance
- The feature vector to be classified.AbstractVectorClassifier.classify(Vector)
public Vector classify(Vector instance)
UnsupportedOperationException
.classify
in class AbstractVectorClassifier
instance
- A feature vector to be classified.n-1
encoding.Copyright © 2008–2017 The Apache Software Foundation. All rights reserved.