This is an automated email from the ASF dual-hosted git repository.

rzo1 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/opennlp.git


The following commit(s) were added to refs/heads/master by this push:
     new 4a5eed8a OPENNLP-1187 Issue in finding accuracy of model
4a5eed8a is described below

commit 4a5eed8a189caa26399c181daaaba9fb5803a294
Author: Martin Wiesner <[email protected]>
AuthorDate: Fri Dec 9 16:43:00 2022 +0100

    OPENNLP-1187 Issue in finding accuracy of model
    
    - adds `NaiveBayesEvalParameters` by computation of the outcome total 
values, as proposed by reporter 'agarg98'
---
 .../java/opennlp/tools/ml/naivebayes/NaiveBayesTrainer.java  | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git 
a/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/NaiveBayesTrainer.java
 
b/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/NaiveBayesTrainer.java
index c56d9cc1..2f3af439 100644
--- 
a/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/NaiveBayesTrainer.java
+++ 
b/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/NaiveBayesTrainer.java
@@ -22,6 +22,7 @@ import java.io.IOException;
 import opennlp.tools.ml.AbstractEventTrainer;
 import opennlp.tools.ml.ArrayMath;
 import opennlp.tools.ml.model.AbstractModel;
+import opennlp.tools.ml.model.Context;
 import opennlp.tools.ml.model.DataIndexer;
 import opennlp.tools.ml.model.EvalParameters;
 import opennlp.tools.ml.model.MutableContext;
@@ -152,7 +153,16 @@ public class NaiveBayesTrainer extends 
AbstractEventTrainer {
         params[pi].setParameter(aoi, 0.0);
     }
 
-    EvalParameters evalParams = new EvalParameters(params, numOutcomes);
+    double[] outcomeTotals = new double[outcomeLabels.length];
+    for (Context context : params) {
+      for (int j = 0; j < context.getOutcomes().length; ++j) {
+        int outcome = context.getOutcomes()[j];
+        double count = context.getParameters()[j];
+        outcomeTotals[outcome] += count;
+      }
+    }
+    EvalParameters evalParams = new NaiveBayesEvalParameters(
+            params, outcomeLabels.length, outcomeTotals, predLabels.length);
 
     double stepSize = 1;
 

Reply via email to