2

我正在 Spark 中训练 NaiveBayesModel,但是当我使用它来预测新实例时,我需要获取每个类的概率。我查看了 NaiveBayesModel 中 predict 函数的代码,得出以下代码:

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, prob)不断给我一个错误,即找不到值'axpy'。

4

1 回答 1

2

在最近的拉取请求中,它被添加到 Spark 主干中,并将在 Spark 1.5 中发布(关闭SPARK-4362)。因此,您可以致电

def predictProbabilities(testData: RDD[Vector]): RDD[Vector]

或者

def predictProbabilities(testData: Vector): Vector

于 2015-08-06T10:00:35.270 回答