Github user rnowling commented on a diff in the pull request:
https://github.com/apache/spark/pull/4087#discussion_r23142579
--- Diff:
mllib/src/main/scala/org/apache/spark/mllib/classification/NaiveBayes.scala ---
@@ -32,28 +42,42 @@ import org.apache.spark.rdd.RDD
* @param pi log of class priors, whose dimension is C, number of labels
* @param theta log of class conditional probabilities, whose dimension is
C-by-D,
* where D is number of features
+ * @param model The type of NB model to fit from the enumeration
NaiveBayesModels, can be
+ * Multinomial or Bernoulli
*/
+
class NaiveBayesModel private[mllib] (
val labels: Array[Double],
val pi: Array[Double],
- val theta: Array[Array[Double]]) extends ClassificationModel with
Serializable {
-
- private val brzPi = new BDV[Double](pi)
- private val brzTheta = new BDM[Double](theta.length, theta(0).length)
+ val theta: Array[Array[Double]],
+ val model: NaiveBayesModels) extends ClassificationModel with
Serializable {
- {
- // Need to put an extra pair of braces to prevent Scala treating `i`
as a member.
+ def populateMatrix(arrayIn: Array[Array[Double]],
+ matrixIn: BDM[Double],
+ transformation: (Double) => Double = (x) => x) = {
var i = 0
- while (i < theta.length) {
+ while (i < arrayIn.length) {
var j = 0
- while (j < theta(i).length) {
- brzTheta(i, j) = theta(i)(j)
+ while (j < arrayIn(i).length) {
+ matrixIn(i, j) = transformation(theta(i)(j))
j += 1
}
i += 1
}
}
+ private val brzPi = new BDV[Double](pi)
+ private val brzTheta = new BDM[Double](theta.length, theta(0).length)
+ populateMatrix(theta, brzTheta)
+
+ private val brzNegTheta: Option[BDM[Double]] = model match {
--- End diff --
Why use an Option if this method is only called for Bernoulli anyway?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]