c语言sscanf函数的用法是什么
273
2022-09-02
Spark mllib SVM
package com.immooc.spark import org.apache.log4j.{Level, Logger} import org.apache.spark.mllib.classification.SVMWithSGD import org.apache.spark.mllib.util.MLUtils import org.apache.spark.{SparkConf, SparkContext} object SparkSVM { def main(args:Array[String]): Unit = { val conf = new SparkConf().setAppName("SparkSVM").setMaster("local[2]") val sc = new SparkContext(conf) Logger.getRootLogger.setLevel(Level.WARN) // 读取样本数据1,格式为LIBSVM format val data = MLUtils.loadLibSVMFile(sc, "file:///Users/walle/Documents/D3/sparkmlib/sample_libsvm_data.txt") //样本数据划分训练样本与测试样本 val splits = data.randomSplit(Array(0.6, 0.4), seed = 11L) val training = splits(0).cache() val test = splits(1) //新建逻辑回归模型,并训练 val numIterations = 100 val model = SVMWithSGD.train(training, numIterations) //对测试样本进行测试 val predictionAndLabel = test.map { point => val score = model.predict(point.features) (score, point.label) } val print_predict = predictionAndLabel.take(20) println("prediction" + "\t" + "label") for (i <- 0 to print_predict.length - 1) { println(print_predict(i)._1 + "\t" + print_predict(i)._2) } // 误差计算 val accuracy = 1.0 * predictionAndLabel.filter(x => x._1 == x._2).count() / test.count() println("Area under ROC = " + accuracy) } }
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~