如何获取类的概率在星火朴素贝叶斯分类? [英] How to get the probabilities of classes in Spark Naive Bayes classifier?

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

问题描述

我在训练火花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.

推荐答案

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

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:矢量):矢量

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆