zhengruifeng commented on a change in pull request #26413: 
[SPARK-16872][ML][PYSPARK] Impl Gaussian Naive Bayes Classifier
URL: https://github.com/apache/spark/pull/26413#discussion_r344431152
 
 

 ##########
 File path: 
mllib/src/main/scala/org/apache/spark/ml/classification/NaiveBayes.scala
 ##########
 @@ -311,24 +432,42 @@ class NaiveBayesModel private[ml] (
       require(value == 0.0 || value == 1.0,
         s"Bernoulli naive Bayes requires 0 or 1 feature values but found 
$features.")
     )
-    val prob = thetaMinusNegTheta.get.multiply(features)
+    val prob = thetaMinusNegTheta.multiply(features)
     BLAS.axpy(1.0, pi, prob)
-    BLAS.axpy(1.0, negThetaSum.get, prob)
+    BLAS.axpy(1.0, negThetaSum, prob)
     prob
   }
 
-  override protected def predictRaw(features: Vector): Vector = {
+  private def gaussianCalculation(features: Vector) = {
+    val prob = Array.ofDim[Double](numClasses)
+    var i = 0
+    while (i < numClasses) {
+      var s = 0.0
+      var j = 0
+      while (j < numFeatures) {
+        val d = features(j) - theta(i, j)
+        s += d * d / sigma(i, j)
+        j += 1
+      }
+      prob(i) = pi(i) - (s + logVarSum(i)) / 2
+      i += 1
+    }
+    Vectors.dense(prob)
+  }
+
+  @transient private lazy val predictRawFunc = {
 
 Review comment:
   Oh it should be lazy, other it will cause:
   ```scala
   java.util.NoSuchElementException: Failed to find a default value for 
modelType
   [info]   at 
org.apache.spark.ml.param.Params.$anonfun$getOrDefault$2(params.scala:780)
   [info]   at scala.Option.getOrElse(Option.scala:189)
   [info]   at org.apache.spark.ml.param.Params.getOrDefault(params.scala:780)
   [info]   at org.apache.spark.ml.param.Params.getOrDefault$(params.scala:777)
   [info]   at org.apache.spark.ml.PipelineStage.getOrDefault(Pipeline.scala:43)
   [info]   at org.apache.spark.ml.param.Params.$(params.scala:786)
   [info]   at org.apache.spark.ml.param.Params.$$(params.scala:786)
   [info]   at org.apache.spark.ml.PipelineStage.$(Pipeline.scala:43)
   [info]   at 
org.apache.spark.ml.classification.NaiveBayesModel.<init>(NaiveBayes.scala:466)
   ```
   
   Since  `NaiveBayesModel` should not contain `setDefault(modelType -> 
NaiveBayes.Multinomial)`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to