1、直接上官方代码,调整过的,方可使用

package com.test
import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.mllib.classification.{LogisticRegressionModel, LogisticRegressionWithLBFGS}
import org.apache.spark.mllib.evaluation.MulticlassMetrics
import org.apache.spark.mllib.regression.LabeledPoint
import org.apache.spark.mllib.util.MLUtils object logsitiRcongin { def main(args: Array[String]): Unit = {
val conf = new SparkConf().setMaster("local").setAppName("df")
val sc = new SparkContext(conf) // Load training data in LIBSVM format.
val data = MLUtils.loadLibSVMFile(sc, "E:\\spackLearn\\spark-2.3.3-bin-hadoop2.7\\data\\mllib\\sample_libsvm_data.txt") // Split data into training (60%) and test (40%).
val splits = data.randomSplit(Array(0.6, 0.4), seed = 11L)
val training = splits(0).cache()
val test = splits(1) // Run training algorithm to build the model
val model = new LogisticRegressionWithLBFGS()
.setNumClasses(10)
.run(training) // Compute raw scores on the test set.
val predictionAndLabels = test.map { case LabeledPoint(label, features) =>
val prediction = model.predict(features)
(prediction, label)
} // Get evaluation metrics.
val metrics = new MulticlassMetrics(predictionAndLabels)
val accuracy = metrics.accuracy
println(s"最后的得分:Accuracy = $accuracy") // Save and load model
model.save(sc, "data/model/scalaLogisticRegressionWithLBFGSModel")
val sameModel = LogisticRegressionModel.load(sc, "data/model/scalaLogisticRegressionWithLBFGSModel") while (true){
} }
}

  

最后查看任务调度

 

成功秀了一波scala spark ML逻辑斯蒂回归的更多相关文章

  1. spark机器学习从0到1逻辑斯蒂回归之(四)

      逻辑斯蒂回归 一.概念 逻辑斯蒂回归(logistic regression)是统计学习中的经典分类方法,属于对数线性模型.logistic回归的因变量可以是二分类的,也可以是多分类的.logis ...

  2. [置顶] 局部加权回归、最小二乘的概率解释、逻辑斯蒂回归、感知器算法——斯坦福ML公开课笔记3

    转载请注明:http://blog.csdn.net/xinzhangyanxiang/article/details/9113681 最近在看Ng的机器学习公开课,Ng的讲法循循善诱,感觉提高了不少 ...

  3. Spark ML逻辑回归

    import org.apache.log4j.{Level, Logger} import org.apache.spark.ml.classification.LogisticRegression ...

  4. Spark ML源码分析之二 从单机到分布式

            前一节从宏观角度给大家介绍了Spark ML的设计框架(链接:http://www.cnblogs.com/jicanghai/p/8570805.html),本节我们将介绍,Spar ...

  5. Extending sparklyr to Compute Cost for K-means on YARN Cluster with Spark ML Library

    Machine and statistical learning wizards are becoming more eager to perform analysis with Spark MLli ...

  6. Spark ML下实现的多分类adaboost+naivebayes算法在文本分类上的应用

    1. Naive Bayes算法 朴素贝叶斯算法算是生成模型中一个最经典的分类算法之一了,常用的有Bernoulli和Multinomial两种.在文本分类上经常会用到这两种方法.在词袋模型中,对于一 ...

  7. Spark ML源码分析之四 树

            之前我们讲过,在Spark ML中所有的机器学习模型都是以参数作为划分的,树相关的参数定义在treeParams.scala这个文件中,这里构建一个关于树的体系结构.首先,以Decis ...

  8. Eclipse+maven+scala+spark环境搭建

    准备条件 我用的Eclipse版本 Eclipse Java EE IDE for Web Developers. Version: Luna Release (4.4.0) 我用的是Eclipse ...

  9. scala spark 机器学习初探

    Transformer: 是一个抽象类包含特征转换器, 和最终的学习模型, 需要实现transformer方法 通常transformer为一个RDD增加若干列, 最终转化成另一个RDD, 1. 特征 ...

随机推荐

  1. PrimeFaces ab function

    The PrimeFaces.ab function is a shortcut function for PrimeFaces.ajax.AjaxRequest. //ajax shortcut a ...

  2. 【译文】Git merge 和 Git rebase比较

    [译文]Git merge 和 Git rebase比较 原创: 胡江华 胡同学和朋友们的成长日记 2017-03-22 git rebase 这个命令经常被人认为是一种Git巫术,初学者应该避而远之 ...

  3. STM32CubeIDE Debug Configurations

    新建完工程并编译后,配置Debug Configurations 此时双击STM32 MCU Debugging,如下图 此时就可以下载调试生成的LED.elf文件了

  4. 【洛谷P2292】L语言

    题目大意:给定一个长度为 N 的字符串和一个字典,字典中所有的字符串的长度均不超过 10,求给定的字符串从前往后最多有多少位可以与字典匹配. 题解:设 \(dp[i]\) 表示串的前 i 位是否能够与 ...

  5. python实例31[生成随即的密码]

    代码: import random import string import time # strong.high = 3  #random for the whole passwd #storng. ...

  6. StyleBundle打包问题—— /* 未能缩小。正在返回未缩小的内容。

    问题--查看打包发布的结果,类似下面的这样的 /* 未能缩小.正在返回未缩小的内容. (1567,65): run-time error CSS1054: JavaScript error in ex ...

  7. ubuntu1604-Python35-cuda9-cudnn7-gpu-dockerfile

    一,在某目录下有如下文件: -rw-r--r-- 1 root root 1643293725 9月 2 11:46 cuda_9.0.176_384.81_linux.run -rw-r--r-- ...

  8. Halcon10.0 + VS2010

    新建一个C++空项目 添加c1.pp 复制example1.cpp的代码 配置include\lib\bin\Linker之后

  9. AttributeError: module 'datetime' has no attribute 'now'

    在用时间转化时,一直报AttributeError: module 'datetime' has no attribute 'now', 我用的 import datetime   datetime ...

  10. (56)Linux驱动开发之二

                                                                                             内核基础   1.li ...