本文整理汇总了Scala中org.apache.spark.mllib.classification.LogisticRegressionModel类的典型用法代码示例。如果您正苦于以下问题:Scala LogisticRegressionModel类的具体用法?Scala LogisticRegressionModel怎么用?Scala LogisticRegressionModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LogisticRegressionModel类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: BinomialValidation
//设置package包名称以及导入依赖的类
package com.bistel.wordcount.logisticRegression
import org.apache.spark.SparkContext
import org.apache.spark.mllib.classification.LogisticRegressionModel
import org.apache.spark.mllib.evaluation.BinaryClassificationMetrics
import org.apache.spark.mllib.regression.LabeledPoint
class BinomialValidation(sc: SparkContext,
model: LogisticRegressionModel,
numTasks: Int) {
def metrics(validationSet: Array[LabeledPoint]): Quality = {
val featuresLabels = validationSet.map(lbPt =>
(lbPt.label, lbPt.features)).unzip
val predicted_rdd = model.predict(
sc.makeRDD(featuresLabels._2, numTasks)
)
val scoreAndLabels = sc.makeRDD(featuresLabels._1,
numTasks).zip(predicted_rdd)
val successes = scoreAndLabels.map {
case (e, p) => Math.abs(e - p)
}.filter(_ < 0.1)
// Mean sum of square errors
val msse = scoreAndLabels.map {
case (e, p) => (e - p) * (e - p)
}.sum
val metrics = new BinaryClassificationMetrics(scoreAndLabels)
Quality(metrics.fMeasureByThreshold().collect,
msse,
successes.count.toDouble / validationSet.length)
}
}