使用 model.predict 时出现 MLlib LogisticRegressionWithLBFGS 错误
MLlib LogisticRegressionWithLBFGS error when using model.predict
我正在使用 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
为什么会这样?模型训练无误。
"model" 定义了您要使用的分类器。
训练模型时不保存它,试试这个;
val classifier = new LogisticRegressionWithLBFGS()
classifier.setNumClasses(5)
val model = classifier.run(trainingData)
我正在使用 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
为什么会这样?模型训练无误。
"model" 定义了您要使用的分类器。
训练模型时不保存它,试试这个;
val classifier = new LogisticRegressionWithLBFGS()
classifier.setNumClasses(5)
val model = classifier.run(trainingData)