Github user srowen commented on the pull request:
https://github.com/apache/spark/pull/6761#issuecomment117248710
Here is roughly the code to compute expected class probabilities for a given piece of
input:
```
def expectedMultinomialProbabilities(model: NaiveBayesModel, testData: Vector) = {
val piVector = new BDV(model.pi)
// model.labels is rowmajor; treat it as colmajor representation of transpose, and
transpose:
val thetaMatrix = new BDM(model.theta(0).length, model.theta.length, model.theta.flatten).t
val logClassProbs = piVector + (thetaMatrix * testData.toBreeze)
logClassProbs.toArray.map(math.exp)
}
def expectedBernoulliProbabilities(model: NaiveBayesModel, testData: Vector) = {
val piVector = new BDV(model.pi)
val thetaMatrix = new BDM(model.theta(0).length, model.theta.length, model.theta.flatten).t
val negThetaMatrix = new BDM(model.theta(0).length, model.theta.length, model.theta.flatten.map(v
=> math.log(1.0  math.exp(v)))).t
val testBreeze = testData.toBreeze
val negTestBreeze = new BDV(Array.fill(testBreeze.size)(1.0))  testBreeze
val logClassProbs = piVector + (thetaMatrix * testBreeze) + (negThetaMatrix * negTestBreeze)
logClassProbs.toArray.map(math.exp)
}
```
I intentionally approached it differently from the implementation in `NaiveBayesModel`;
this is probably more straightforward but less performant, but that's the point of a crosscheck
in a test I suppose.
I haven't tested it; maybe I can test my test tomorrow. It should at least compile and
be 90+% there.

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 infrastructure@apache.org or file a JIRA ticket
with INFRA.


To unsubscribe, email: reviewsunsubscribe@spark.apache.org
For additional commands, email: reviewshelp@spark.apache.org
