Class NaiveBayesModel
java.lang.Object
opennlp.tools.ml.model.AbstractModel
opennlp.tools.ml.naivebayes.NaiveBayesModel
- All Implemented Interfaces:
MaxentModel
A
MaxentModel implementation of the multinomial Naive Bayes classifier model.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractModel
AbstractModel.ModelType -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final double[]protected longFields inherited from class AbstractModel
evalParams, modelType, outcomeNames, pmap, prior -
Constructor Summary
ConstructorsConstructorDescriptionNaiveBayesModel(Context[] params, String[] predLabels, String[] outcomeNames) Initializes aNaiveBayesModel.NaiveBayesModel(Context[] params, String[] predLabels, Map<String, Context> pmap, String[] outcomeNames) Initializes aNaiveBayesModel. -
Method Summary
Modifier and TypeMethodDescriptionstatic double[]eval(int[] context, double[] prior, EvalParameters model) Evaluates aNaiveBayesModel.(package private) static double[]eval(int[] context, float[] values, double[] prior, EvalParameters model, boolean normalize) Evaluates aNaiveBayesModel.double[]Evaluates acontext.double[]Evaluates acontext.double[]Evaluates acontextwith the specified contextvalues.double[](package private) static double[]eval(Context[] context, float[] values, double[] prior, EvalParameters model, boolean normalize) Evaluates aNaiveBayesModel.private static doublegetProbability(double numerator, double denominator, double vocabulary, boolean isSmoothed) private static doublegetSmoothedProbability(double numerator, double denominator, double vocabulary) protected double[]initOutcomeTotals(String[] outcomeNames, Context[] params) Methods inherited from class AbstractModel
equals, getAllOutcomes, getBestOutcome, getDataStructures, getIndex, getModelType, getNumOutcomes, getOutcome, hashCode
-
Field Details
-
outcomeTotals
protected final double[] outcomeTotals -
vocabulary
protected long vocabulary
-
-
Constructor Details
-
NaiveBayesModel
NaiveBayesModel(Context[] params, String[] predLabels, Map<String, Context> pmap, String[] outcomeNames) Initializes aNaiveBayesModel.- Parameters:
params- Theparametersto set.predLabels- The predicted labels.pmap- AMapthat provides a mapping between predicates and contexts.outcomeNames- The names of the outcomes.
-
NaiveBayesModel
Initializes aNaiveBayesModel.- Parameters:
params- Theparametersto set.predLabels- The predicted labels.outcomeNames- The names of the outcomes.
-
-
Method Details
-
initOutcomeTotals
-
eval
Evaluates acontext.- Parameters:
context- An array of String names of the contextual predicates which are to be evaluated together.- Returns:
- An array of the probabilities for each of the different
outcomes, all of which sum to
1.
-
eval
Evaluates acontextwith the specified contextvalues.- Parameters:
context- An array of String names of the contextual predicates which are to be evaluated together.values- The values associated with each context.- Returns:
- An array of the probabilities for each of the different
outcomes, all of which sum to
1.
-
eval
Evaluates acontext.- Parameters:
context- An array of String names of the contextual predicates which are to be evaluated together.probs- An array which is populated with the probabilities for each of the different outcomes, all of which sum to 1.- Returns:
- An array of the probabilities for each of the different
outcomes, all of which sum to
1.
-
eval
-
eval
Evaluates aNaiveBayesModel.- Parameters:
context- The context parameters asint[].prior- The data prior to the evaluation asdouble[].model- TheEvalParametersused for evaluation.- Returns:
- The resulting evaluation data as
double[].
-
eval
static double[] eval(Context[] context, float[] values, double[] prior, EvalParameters model, boolean normalize) Evaluates aNaiveBayesModel.- Parameters:
context- Theparametersto set..values- Thefloat[]values to be used.prior- The data prior to the evaluation asdouble[].model- TheEvalParametersused for evaluation.normalize- Whether to normalize, or not.- Returns:
- The resulting evaluation data as
double[].
-
eval
static double[] eval(int[] context, float[] values, double[] prior, EvalParameters model, boolean normalize) Evaluates aNaiveBayesModel.- Parameters:
context- The context parameters asint[].values- Thefloat[]values to be used.prior- The data prior to the evaluation asdouble[].model- TheEvalParametersused for evaluation.normalize- Whether to normalize, or not.- Returns:
- The resulting evaluation data as
double[].
-
getProbability
private static double getProbability(double numerator, double denominator, double vocabulary, boolean isSmoothed) -
getSmoothedProbability
private static double getSmoothedProbability(double numerator, double denominator, double vocabulary)
-