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_r344431188
 
 

 ##########
 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:
   I found that VectorIndexerModel also mark 
[transformFunc](https://github.com/apache/spark/blob/ed12b61784e2ce5a1779c162bde1e16e9a9a0135/mllib/src/main/scala/org/apache/spark/ml/feature/VectorIndexer.scala#L351)
 lazy.

----------------------------------------------------------------
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