如何获取类的概率在星火朴素贝叶斯分类

如何获取类的概率在星火朴素贝叶斯分类

本文介绍了如何获取类的概率在星火朴素贝叶斯分类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在训练火花NaiveBayesModel,但是当我用它来predict一个新的实例,我需要得到每个类的概率。我看了看predict功能的NaiveBayesModel的code和拿出以下code:

I'm training a NaiveBayesModel in Spark, however when I'm using it to predict a new instance I need to get the probabilities for each class. I looked at the code of predict function in NaiveBayesModel and come up with the following code:

val thetaMatrix = new DenseMatrix (model.labels.length,model.theta(0).length,model.theta.flatten,true)
val piVector = new DenseVector(model.pi)
//val prob = thetaMatrix.multiply(test.features)

val x = test.map {p =>
  val prob = thetaMatrix.multiply(p.features)
  BLAS.axpy(1.0, piVector, prob)
  prob
}

正常工作的呢?行 BLAS.axpy(1.0,piVector,概率)一直给我的价值axpy'没有发现错误。

Does this work properly? The line BLAS.axpy(1.0, piVector, prob) keeps giving me an error that the value 'axpy' is not found.

推荐答案

在最近的这被添加到星火干线,将在星火1.5(关闭的)。因此,你可以叫

In a recent pull-request this was added to the Spark trunk and will be released in Spark 1.5 (closing SPARK-4362). you can therefore call

DEF predictProbabilities(TESTDATA:RDD [矢量]):RDD [矢量]

DEF predictProbabilities(TESTDATA:矢量):矢量

这篇关于如何获取类的概率在星火朴素贝叶斯分类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 18:36