|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectir.classifiers.Classifier
ir.classifiers.NaiveBayes
public class NaiveBayes
Implements the NaiveBayes Classifier with Laplace smoothing. Stores probabilities internally as logs to prevent underflow problems.
| Field Summary | |
|---|---|
static java.lang.String |
name
Name of classifier |
| Fields inherited from class ir.classifiers.Classifier |
|---|
categories, random |
| Constructor Summary | |
|---|---|
NaiveBayes(java.lang.String[] categories,
boolean debug)
Create a naive Bayes classifier with these attributes |
|
| Method Summary | |
|---|---|
protected double[] |
calculatePriors(java.util.List<Example> trainExamples)
Calculates the class priors |
protected double[] |
calculateProbs(Example testExample)
Calculates the prob of the testExample being generated by each category |
protected java.util.Hashtable<java.lang.String,double[]> |
conditionalProbs(java.util.List<Example> trainExamples)
Calculates the conditional probs of each feature in the different categories |
protected void |
displayProbs(double[] classPriors,
java.util.Hashtable<java.lang.String,double[]> featureHash)
Displays the probs for each feature in the different categories |
double |
getEpsilon()
Returns value of EPSILON |
boolean |
getIsLaplace()
Returns value of isLaplace |
java.lang.String |
getName()
Returns the name |
BayesResult |
getTrainResult()
Returns training result |
void |
setDebug(boolean bool)
Sets the debug flag |
void |
setEpsilon(double ep)
Sets the value of EPSILON (default 1e-6) |
void |
setLaplace(boolean bool)
Sets the Laplace smoothing flag |
boolean |
test(Example testExample)
Categorizes the test example using the trained Naive Bayes classifier, returning true if the predicted category is same as the actual category |
void |
train(java.util.List<Example> trainExamples)
Trains the Naive Bayes classifier - estimates the prior probs and calculates the counts for each feature in different categories |
| Methods inherited from class ir.classifiers.Classifier |
|---|
argMax, getCategories |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String name
| Constructor Detail |
|---|
public NaiveBayes(java.lang.String[] categories,
boolean debug)
categories - The array of Strings containing the category namesdebug - Flag to turn on detailed output| Method Detail |
|---|
public void setDebug(boolean bool)
public void setLaplace(boolean bool)
public void setEpsilon(double ep)
public java.lang.String getName()
getName in class Classifierpublic double getEpsilon()
public BayesResult getTrainResult()
public boolean getIsLaplace()
public void train(java.util.List<Example> trainExamples)
train in class ClassifiertrainExamples - The vector of training examplespublic boolean test(Example testExample)
test in class ClassifiertestExample - The test example to be categorizedprotected double[] calculatePriors(java.util.List<Example> trainExamples)
trainExamples - The training examples from which class priors will be estimatedprotected java.util.Hashtable<java.lang.String,double[]> conditionalProbs(java.util.List<Example> trainExamples)
trainExamples - The training examples from which counts will be estimatedprotected double[] calculateProbs(Example testExample)
testExample - The test example to be categorized
protected void displayProbs(double[] classPriors,
java.util.Hashtable<java.lang.String,double[]> featureHash)
classPriors - Prior probsfeatureHash - Feature hashtable after training
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||