|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.ObjectLBJ2.classify.Classifier
LBJ2.learn.Learner
LBJ2.learn.NaiveBayes
public class NaiveBayes
Naive Bayes is a multi-class learner that uses prediction value counts and feature counts given a particular prediction value to select the most likely prediction value. More precisely, a score sv for a given prediction value v is computed such that esv is proportional to
P(v) Prodf P(f|v)where Prod is a multiplication quantifier over f, and f stands for a feature. The value corresponding to the highest score is selected as the prediction. Feature values that were never observed given a particular prediction value during training are smoothed with a configurable constant that defaults to e-15.
This Learner learns a discrete classifier from
other discrete classifiers. Features coming from
real classifiers are ignored. It is also assumed that a
single discrete label feature will be produced in association with each
example object. A feature taking one of the values observed in that label
feature will be produced by the learned classifier.
This algorithm's user-configurable parameters are stored in member
fields of this class. They may be set via either a constructor that names
each parameter explicitly or a constructor that takes an instance of
Parameters as input. The
documentation in each member field in this class indicates the default
value of the associated parameter when using the former type of
constructor. The documentation of the associated member field in the
Parameters class indicates the
default value of the parameter when using the latter type of constructor.
NaiveBayes.NaiveBayesVector,
Serialized Form| Nested Class Summary | |
|---|---|
protected static class |
NaiveBayes.Count
A Count object stores two doubles, one which
holds a accumulated count value and the other intended to hold the
natural logarithm of the count. |
protected class |
NaiveBayes.NaiveBayesVector
Keeps track of all the counts associated with a given label. |
static class |
NaiveBayes.Parameters
Simply a container for all of NaiveBayes's configurable
parameters. |
| Field Summary | |
|---|---|
static int |
defaultSmoothing
The default conditional feature probability is e defaultSmoothing. |
protected java.util.LinkedHashMap |
network
One NaiveBayes.NaiveBayesVector for each observed prediction value. |
protected double |
smoothing
The exponential of this number is used as the conditional probability of a feature that was never observed during training; default defaultSmoothing. |
| Fields inherited from class LBJ2.learn.Learner |
|---|
extractor, labeler |
| Fields inherited from class LBJ2.classify.Classifier |
|---|
containingPackage, name |
| Constructor Summary | |
|---|---|
NaiveBayes()
Default constructor. |
|
NaiveBayes(double smooth)
Initializes the smoothing constant. |
|
NaiveBayes(NaiveBayes.Parameters p)
Initializing constructor. |
|
NaiveBayes(java.lang.String n)
Initializes the name of the classifier. |
|
NaiveBayes(java.lang.String name,
double smooth)
Initializes the name and smoothing constant. |
|
NaiveBayes(java.lang.String n,
NaiveBayes.Parameters p)
Initializing constructor. |
|
| Method Summary | |
|---|---|
FeatureVector |
classify(java.lang.Object example)
Prediction value counts and feature counts given a particular prediction value are used to select the most likely prediction value. |
java.lang.Object |
clone()
Returns a deep clone of this learning algorithm. |
void |
forget()
Clears the network. |
void |
learn(java.lang.Object example)
Trains the learning algorithm given an object as an example. |
ScoreSet |
scores(java.lang.Object example)
The scores in the returned ScoreSet are the posterior
probabilities of each possible label given the example. |
void |
setLabeler(Classifier l)
Sets the labeler. |
void |
setSmoothing(double s)
Sets the smoothing parameter to the specified value. |
void |
write(java.io.PrintStream out)
Writes the algorithm's internal representation as text. |
| Methods inherited from class LBJ2.learn.Learner |
|---|
doneLearning, getExtractor, getLabeler, learn, save, setExtractor |
| Methods inherited from class LBJ2.classify.Classifier |
|---|
allowableValues, binaryRead, binaryRead, binaryRead, binaryRead, binaryWrite, binaryWrite, classify, discreteValue, discreteValueArray, getCompositeChildren, getInputType, getOutputType, realValue, realValueArray, test, toString, valueIndexOf |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int defaultSmoothing
defaultSmoothing.
protected double smoothing
defaultSmoothing.
protected java.util.LinkedHashMap network
NaiveBayes.NaiveBayesVector for each observed prediction value.
| Constructor Detail |
|---|
public NaiveBayes()
public NaiveBayes(double smooth)
smooth - The exponential of this number is used as the conditional
probability of a feature that was never observed during
training.public NaiveBayes(NaiveBayes.Parameters p)
NaiveBayes.Parameters object.
p - The settings of all parameters.public NaiveBayes(java.lang.String n)
n - The classifier's name.
public NaiveBayes(java.lang.String name,
double smooth)
name - The classifier's name.smooth - The exponential of this number is used as the conditional
probability of a feature that was never observed during
training.
public NaiveBayes(java.lang.String n,
NaiveBayes.Parameters p)
NaiveBayes.Parameters object.
n - The name of the classifier.p - The settings of all parameters.| Method Detail |
|---|
public void setSmoothing(double s)
s - The new value for the smoothing parameter.public void setLabeler(Classifier l)
setLabeler in class Learnerl - A labeling classifier.public void learn(java.lang.Object example)
learn in class Learnerexample - An example of the desired learned classifier's behavior.public void forget()
forget in class Learnerpublic ScoreSet scores(java.lang.Object example)
ScoreSet are the posterior
probabilities of each possible label given the example.
scores in class Learnerexample - The object to make decisions about.
public FeatureVector classify(java.lang.Object example)
classify in class Classifierexample - The example object.
public void write(java.io.PrintStream out)
write in class Learnerout - The output stream.public java.lang.Object clone()
clone in class Classifier
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||