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

mboehm7 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/systemds.git


The following commit(s) were added to refs/heads/main by this push:
     new 4073206a1a [MINOR] Fix misleading documentation naiveBayes and 
naiveBayesPredict
4073206a1a is described below

commit 4073206a1a46cfc6e03628ae699f36f9174c664f
Author: Matthias Boehm <mboe...@gmail.com>
AuthorDate: Thu Apr 11 20:37:32 2024 +0200

    [MINOR] Fix misleading documentation naiveBayes and naiveBayesPredict
---
 scripts/builtin/naiveBayes.dml        | 33 +++++++++++++++++----------------
 scripts/builtin/naiveBayesPredict.dml | 19 ++++++++++---------
 2 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/scripts/builtin/naiveBayes.dml b/scripts/builtin/naiveBayes.dml
index d6e2028a5d..7f01fe9378 100644
--- a/scripts/builtin/naiveBayes.dml
+++ b/scripts/builtin/naiveBayes.dml
@@ -19,21 +19,21 @@
 #
 #-------------------------------------------------------------
 
-# The naiveBayes-function computes the class conditional probabilities and 
class priors.
+# This builtin function implements a NaiveBayes classification.
 #
 # INPUT:
-# 
----------------------------------------------------------------------------------------
-# D        One dimensional column matrix with N rows.
-# C        One dimensional column matrix with N rows.
-# laplace  Any Double value.
-# verbose  Boolean value.
-# 
----------------------------------------------------------------------------------------
+# 
------------------------------------------------------------------------------
+# D        Input feature matrix of shape N x M
+# C        Class label vector (positive integers) of shape N x 1.
+# laplace  Laplace smoothing correction (prevent zero probabilities)
+# verbose  Flag for verbose debug output
+# 
------------------------------------------------------------------------------
 #
 # OUTPUT:
-# 
--------------------------------------------------------------------------------------------------
-# prior              Class priors, One dimensional column matrix with N rows.
-# classConditionals  Class conditional probabilities, One dimensional column 
matrix with N rows.
-# 
--------------------------------------------------------------------------------------------------
+# 
------------------------------------------------------------------------------
+# prior              Class prior probabilities
+# classConditionals  Class conditional feature distributions
+# 
------------------------------------------------------------------------------
 
 m_naiveBayes = function(Matrix[Double] D,
   Matrix[Double] C, Double laplace = 1, Boolean verbose = TRUE)
@@ -49,18 +49,18 @@ m_naiveBayes = function(Matrix[Double] D,
   # sanity checks of data and arguments
   if(minFeatureVal < 0)
     stop("naiveBayes: Stopping due to invalid argument: Multinomial naive 
Bayes "
-       + " is meant for count-based feature values, minimum value in X is 
negative")
+       + " is meant for count-based feature values, minimum value in D is 
negative")
   if(numRows < 2)
     stop("naiveBayes: Stopping due to invalid inputs: "
        + "Not possible to learn a classifier without at least 2 rows")
   if(minLabelVal < 1)
-    stop("naiveBayes: Stopping due to invalid argument: Label vector (Y) must 
be recoded")
+    stop("naiveBayes: Stopping due to invalid argument: Label vector (C) must 
be recoded")
   if(numClasses == 1)
     stop("naiveBayes: Stopping due to invalid argument: "
-       + "Maximum label value is 1, need more than one class to learn a 
multi-class classifier")       
+       + "Maximum label value is 1, need more than one class to learn a 
multi-class classifier")
   if(sum(abs(C%%1 == 0)) != numRows)
-    stop("naiveBayes: Stopping due to invalid argument: " 
-       + "Please ensure that Y contains (positive) integral labels")
+    stop("naiveBayes: Stopping due to invalid argument: "
+       + "Please ensure that C contains (positive) integral labels")
   if(laplaceCorrection < 0)
     stop("naiveBayes: Stopping due to invalid argument: "
        + "Laplacian correction (laplace) must be non-negative")
@@ -88,3 +88,4 @@ m_naiveBayes = function(Matrix[Double] D,
     print("Training Accuracy (%): " + acc);
   }
 }
+
diff --git a/scripts/builtin/naiveBayesPredict.dml 
b/scripts/builtin/naiveBayesPredict.dml
index 2d3615eff4..65c6b04d50 100644
--- a/scripts/builtin/naiveBayesPredict.dml
+++ b/scripts/builtin/naiveBayesPredict.dml
@@ -19,20 +19,20 @@
 #
 #-------------------------------------------------------------
 
-# The naiveBaysePredict-function predicts the scoring with a naive Bayes model.
+# This builtin function implements the prediction for NaiveBayes 
classification.
 #
 # INPUT:
-# 
---------------------------------------------------------------------------------------
+# 
------------------------------------------------------------------------------
 # X     Matrix of test data with N rows.
-# P     Class priors, One dimensional column matrix with N rows.
-# C     Class conditional probabilities, matrix with N rows
-# 
---------------------------------------------------------------------------------------
+# P     Class prior probabilities
+# C     Class conditional feature distributions
+# 
------------------------------------------------------------------------------
 #
 # OUTPUT:
-# 
---------------------------------------------------------------------------------------
-# Y     A matrix containing the top-K item-ids with highest predicted ratings.
-# YRaw  A matrix containing predicted ratings.
-# 
---------------------------------------------------------------------------------------
+# 
------------------------------------------------------------------------------
+# Y     A matrix containing the top-K item-ids with highest predicted class.
+# YRaw  A matrix containing predicted class.
+# 
------------------------------------------------------------------------------
 
 m_naiveBayesPredict = function(Matrix[Double] X, Matrix[Double] P, 
Matrix[Double] C)
  return (Matrix[Double] YRaw, Matrix[Double] Y)
@@ -45,3 +45,4 @@ m_naiveBayesPredict = function(Matrix[Double] X, 
Matrix[Double] P, Matrix[Double
   YRaw = X_w_ones %*% t(log(model));
   Y = rowIndexMax(YRaw);
 }
+

Reply via email to