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的更多相关文章

  1. 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 ...

  2. Spark MLlib - Decision Tree源码分析

    http://spark.apache.org/docs/latest/mllib-decision-tree.html 以决策树作为开始,因为简单,而且也比较容易用到,当前的boosting或ran ...

  3. Spark MLlib知识点学习整理

    MLlib的设计原理:把数据以RDD的形式表示,然后在分布式数据集上调用各种算法.MLlib就是RDD上一系列可供调用的函数的集合. 操作步骤: 1.用字符串RDD来表示信息. 2.运行MLlib中的 ...

  4. spark MLLib的基础统计部分学习

    参考学习链接:http://www.itnose.net/detail/6269425.html 机器学习相关算法,建议初学者去看看斯坦福的机器学习课程视频:http://open.163.com/s ...

  5. spark MLlib BasicStatistics 统计学基础

    一, jar依赖,jsc创建. package ML.BasicStatistics; import com.google.common.collect.Lists; import org.apach ...

  6. Spark MLlib 机器学习

    本章导读 机器学习(machine learning, ML)是一门涉及概率论.统计学.逼近论.凸分析.算法复杂度理论等多领域的交叉学科.ML专注于研究计算机模拟或实现人类的学习行为,以获取新知识.新 ...

  7. RandomForest in Spark MLLib

    决策树类模型 ml中的classification和regression主要基于以下几类: classification:决策树及其相关的集成算法,Logistics回归,多层感知模型: regres ...

  8. Spark Mllib里的卡方检验

    不多说,直接上干货! import org.apache.spark.mllib.stat.Statistics 具体,见 Spark Mllib机器学习实战的第4章 Mllib基本数据类型和Mlli ...

  9. Spark Mllib里的如何对单个数据集用斯皮尔曼计算相关系数

    不多说,直接上干货! import org.apache.spark.mllib.stat.Statistics 具体,见 Spark Mllib机器学习实战的第4章 Mllib基本数据类型和Mlli ...

随机推荐

  1. OpenCV2的Mat矩阵形式自定义初始化

    我们知道,OpenCV2的矩阵形式是Mat,那么Mat矩阵的初始化怎么自定义呢 ?由于比较简单,文字部分我就不多加说明了,见代码,有下面几种: //////////////////////////// ...

  2. 13 个免费的 PNG 图像的优化和压缩工具

    图像格式有许多种不同类型,在互联网上最常见的有JPEG.GIF.BMP.TIFF和PNG.每一种图像格式都有它自己的用途,比如GIF是用于动画的,JPEG是用于高清图片的,这种图片在保存或者调整大小后 ...

  3. JAVA 线程中的异常捕获

    在java多线程程序中,所有线程都不允许抛出未捕获的checked exception(比如sleep时的InterruptedException),也就是说各个线程需要自己把自己的checked e ...

  4. 收集C#常用类:对图片的处理操作

    using System; using System.Collections; using System.IO; using System.Drawing; using System.Drawing. ...

  5. 小tip:关于typeof,instanceof,toString(),valueOf(),toLocaleString(),join(),reverse(),sort(),pop(),push(),shift(),unshift()

    typeof:用于检测一个变量是否是基本数据类型.instanceof用于检测某引用对象是什么类型的对象. var s = "Nicho"; var b = true; var n ...

  6. How (not) to trigger a layout in WebKit

    As most web developers are aware, a significant amount of a script's running time may be spent perfo ...

  7. PDF 补丁丁 0.5.0.2520 测试版发布:新春快乐!

    新的PDF测试版今天发布了. 新的测试版比旧测试版本增加了如下功能: 合并文件功能可以导出.导入文件列表,方便合并大量文件.一天干不完,保存一下,明天继续来. 合并文件功能可以统一已合并文件的旋转方向 ...

  8. curl --connect-timeout 判断国内外网络windows 批处理

    1.下载编译curl curl 下载地址:http://curl.haxx.se/download.html ,下载后解压到一个目录,使用vs开发者工具里的 “Visual Studio 命令提示(2 ...

  9. iOS开启隐藏文件以及显示文件方法

    显示:defaults write com.apple.finder AppleShowAllFiles -bool true 隐藏:defaults write com.apple.finder A ...

  10. LeetCode 201 Bitwise AND of Numbers Range 位运算 难度:0

    https://leetcode.com/problems/bitwise-and-of-numbers-range/ [n,m]区间的合取总值就是n,m对齐后前面一段相同的数位的值 比如 5:101 ...