Spark MLlib 之 Basic Statistics
Spark MLlib提供了一些基本的统计学的算法,下面主要说明一下:
1、Summary statistics
对于RDD[Vector]类型,Spark MLlib提供了colStats的统计方法,该方法返回一个MultivariateStatisticalSummary的实例。他封装了列的最大值,最小值,均值、方差、总数。如下所示:
val conf = new SparkConf().setAppName("Simple Application").setMaster("yarn-cluster")
val sc = new SparkContext(conf)
val observations = sc.textFile("/user/liujiyu/spark/mldata1.txt")
.map(_.split(' ') // 转换为RDD[Array[String]]类型
.map(_.toDouble)) // 转换为RDD[Array[Double]]类型
.map(line => Vectors.dense(line)) //转换为RDD[Vector]类型
// Compute column summary statistics.
val summary: MultivariateStatisticalSummary = Statistics.colStats(observations)
println(summary.mean) // a dense vector containing the mean value for each column
println(summary.variance) // column-wise variance
println(summary.numNonzeros) // number of nonzeros in each column
2、Correlations(相关性)
计算两个序列的相关性,提供了计算Pearson’s and Spearman’s correlation.如下所示:
val conf = new SparkConf().setAppName("Simple Application").setMaster("yarn-cluster")
val sc = new SparkContext(conf)
val observations = sc.textFile("/user/liujiyu/spark/mldata1.txt")
val data1 = Array(1.0, 2.0, 3.0, 4.0, 5.0)
val data2 = Array(1.0, 2.0, 3.0, 4.0, 5.0)
val distData1: RDD[Double] = sc.parallelize(data1)
val distData2: RDD[Double] = sc.parallelize(data2) // must have the same number of partitions and cardinality as seriesX
// compute the correlation using Pearson's method. Enter "spearman" for Spearman's method. If a
// method is not specified, Pearson's method will be used by default.
val correlation: Double = Statistics.corr(distData1, distData2, "pearson")
val data: RDD[Vector] = observations // note that each Vector is a row and not a column
// calculate the correlation matrix using Pearson's method. Use "spearman" for Spearman's method.
// If a method is not specified, Pearson's method will be used by default.
val correlMatrix: Matrix = Statistics.corr(data, "pearson")
Spark MLlib 之 Basic Statistics的更多相关文章
- spark mllib docs,MLlib: RDD-based API
MLlib: RDD-based API This page documents sections of the MLlib guide for the RDD-based API (the spar ...
- Spark MLlib - Decision Tree源码分析
http://spark.apache.org/docs/latest/mllib-decision-tree.html 以决策树作为开始,因为简单,而且也比较容易用到,当前的boosting或ran ...
- Spark MLlib知识点学习整理
MLlib的设计原理:把数据以RDD的形式表示,然后在分布式数据集上调用各种算法.MLlib就是RDD上一系列可供调用的函数的集合. 操作步骤: 1.用字符串RDD来表示信息. 2.运行MLlib中的 ...
- spark MLLib的基础统计部分学习
参考学习链接:http://www.itnose.net/detail/6269425.html 机器学习相关算法,建议初学者去看看斯坦福的机器学习课程视频:http://open.163.com/s ...
- spark MLlib BasicStatistics 统计学基础
一, jar依赖,jsc创建. package ML.BasicStatistics; import com.google.common.collect.Lists; import org.apach ...
- Spark MLlib 机器学习
本章导读 机器学习(machine learning, ML)是一门涉及概率论.统计学.逼近论.凸分析.算法复杂度理论等多领域的交叉学科.ML专注于研究计算机模拟或实现人类的学习行为,以获取新知识.新 ...
- RandomForest in Spark MLLib
决策树类模型 ml中的classification和regression主要基于以下几类: classification:决策树及其相关的集成算法,Logistics回归,多层感知模型: regres ...
- Spark Mllib里的卡方检验
不多说,直接上干货! import org.apache.spark.mllib.stat.Statistics 具体,见 Spark Mllib机器学习实战的第4章 Mllib基本数据类型和Mlli ...
- Spark Mllib里的如何对单个数据集用斯皮尔曼计算相关系数
不多说,直接上干货! import org.apache.spark.mllib.stat.Statistics 具体,见 Spark Mllib机器学习实战的第4章 Mllib基本数据类型和Mlli ...
随机推荐
- could not read symbols: File format not recognized
arm-linux-gnueabi-readelf工具解决问题 编译一个32位平台的内核时,出现如下错误提示: libschw.a: could not read symbols: File form ...
- SPSS中两种重复测量资料分析过程的比较
在SPSS中,有两个过程可以对重复测量资料进行分析:一种是一般线性模型的重复度量:一种是混合线性模型,对于同样的数据资料,使用两种过程分析出的内容不大一样,注意是内容而不是结果,只要操作正确,结果应该 ...
- 【burp】配置HTTPS抓包方法
以Chrome为例,配置HTTPS抓包方法 1.获取破解版的burp,将BurpLoader.jar和burpsuite_pro_v1.5.18.jar放到一个路径下 2.在cmd里进入上述两个jar ...
- mybatis高级(2)_数据库中的列和实体类不匹配时的两种解决方法_模糊查询_智能标签
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "- ...
- 学习PYTHON之路, DAY 7 - PYTHON 基础 7 (面向对象基础)
面向对象三大特性 一.封装 封装,顾名思义就是将内容封装到某个地方,以后再去调用被封装在某处的内容. 所以,在使用面向对象的封装特性时,需要: 将内容封装到某处 从某处调用被封装的内容 第一步:将内容 ...
- JSP自定义标签/自定义标签打包
有这样一个业务需求: 当我们在编辑某个用户时,需要设置该用户的角色,在转到编辑页面时,就需要自动勾选上该用户已经选择的角色,如下图: 当我们点击编辑时,会查询用户详细信息,以及角色集合传到编辑页面. ...
- Excel学习技巧
ctrl+R 初始化信息 ctrl+T 创建表列 ctrl+o 保存文件
- μC/OS-Ⅲ系统的中断管理
一.典型的μC/OS-Ⅲ中断服务程序解析 μC/OS-Ⅲ系统中典型有内核参与中断服务程序示例如下: MyISR: ...
- Cannot send session cache limiter Cannot modify header information
当php报出 Cannot send session cache limiter 或Cannot modify header information 的错误时 其理论上是因为php代码以前有 ...
- java中的反射机制在Android开发中的用处
JAVA反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对于任意一个对象,都能够调用它的任意一个方法和属性:这种动态获取的信息以及动态调用对象的方法的功能称为java语言的反 ...