【问题标题】:MLlib LogisticRegressionWithLBFGS error when using model.predict使用 model.predict 时出现 MLlib LogisticRegressionWithLBFGS 错误
【发布时间】:2016-05-24 22:21:16
【问题描述】:

我正在使用 MLlib 的 LogisticRegressionWithLBFGS 来训练具有 4 个类的模型。

这是准备我的数据的代码,

val labeledTraining = trainingSetVectors.map{case(target,features) => LabeledPoint(target,features) }.cache()

val Array(trainingData, testData) = labeledTraining.randomSplit(Array(0.7, 0.3))

训练模型,

val model = new LogisticRegressionWithLBFGS()
model.setNumClasses(5)
model.run(trainingData)

当我尝试测试模型时出现错误

val labelAndPreds = testData.map { Labeledpoint =>
  val prediction = model.predict(LabeledPoint.features)
  (LabeledPoint.target, prediction)
}

error: value predict is not a member of org.apache.spark.mllib.classification.LogisticRegressionWithLBFGS

为什么会这样?模型训练没有任何错误。

【问题讨论】:

  • 因为它没有。您训练并立即丢弃模型。你所说的模型只是一种算法描述。

标签: apache-spark apache-spark-mllib


【解决方案1】:

“模型”是定义你要使用的分类器。

当你训练模型时你没有保存它,试试这个;

val classifier = new LogisticRegressionWithLBFGS()
classifier.setNumClasses(5)
val model = classifier.run(trainingData)

【讨论】:

猜你喜欢
  • 2022-01-22
  • 2016-10-25
  • 2016-10-05
  • 1970-01-01
  • 2019-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-20
相关资源
最近更新 更多