二、MLlib统计指标之关联/抽样/汇总
- import org.apache.spark.api.java.JavaRDD;
- import org.apache.spark.api.java.JavaSparkContext;
- import org.apache.spark.mllib.linalg.Vector;
- import org.apache.spark.mllib.stat.MultivariateStatisticalSummary;
- import org.apache.spark.mllib.stat.Statistics;
- JavaSparkContext jsc = ...
- JavaRDD<Vector> mat = ... // an RDD of Vectors
- // Compute column summary statistics.
- MultivariateStatisticalSummary summary = Statistics.colStats(mat.rdd());
- System.out.println(summary.mean()); // a dense vector containing the mean value for each column
- System.out.println(summary.variance()); // column-wise variance
- System.out.println(summary.numNonzeros()); // number of nonzeros in each column
- import org.apache.spark.api.java.JavaDoubleRDD;
- import org.apache.spark.api.java.JavaSparkContext;
- import org.apache.spark.mllib.linalg.*;
- import org.apache.spark.mllib.stat.Statistics;
- JavaSparkContext jsc = ...
- JavaDoubleRDD seriesX = ... // a series
- JavaDoubleRDD seriesY = ... // 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.
- Double correlation = Statistics.corr(seriesX.srdd(), seriesY.srdd(), "pearson");
- JavaRDD<Vector> data = ... // 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.
- Matrix correlMatrix = Statistics.corr(data.rdd(), "pearson");
- import java.util.Map;
- import org.apache.spark.api.java.JavaPairRDD;
- import org.apache.spark.api.java.JavaSparkContext;
- JavaSparkContext jsc = ...
- JavaPairRDD<K, V> data = ... // an RDD of any key value pairs
- Map<K, Object> fractions = ... // specify the exact fraction desired from each key
- // Get an exact sample from each stratum
- JavaPairRDD<K, V> approxSample = data.sampleByKey(false, fractions);
- JavaPairRDD<K, V> exactSample = data.sampleByKeyExact(false, fractions);
- import org.apache.spark.api.java.JavaRDD;
- import org.apache.spark.api.java.JavaSparkContext;
- import org.apache.spark.mllib.linalg.*;
- import org.apache.spark.mllib.regression.LabeledPoint;
- import org.apache.spark.mllib.stat.Statistics;
- import org.apache.spark.mllib.stat.test.ChiSqTestResult;
- JavaSparkContext jsc = ...
- Vector vec = ... // a vector composed of the frequencies of events
- // compute the goodness of fit. If a second vector to test against is not supplied as a parameter,
- // the test runs against a uniform distribution.
- ChiSqTestResult goodnessOfFitTestResult = Statistics.chiSqTest(vec);
- // summary of the test including the p-value, degrees of freedom, test statistic, the method used,
- // and the null hypothesis.
- System.out.println(goodnessOfFitTestResult);
- Matrix mat = ... // a contingency matrix
- // conduct Pearson's independence test on the input contingency matrix
- ChiSqTestResult independenceTestResult = Statistics.chiSqTest(mat);
- // summary of the test including the p-value, degrees of freedom...
- System.out.println(independenceTestResult);
- JavaRDD<LabeledPoint> obs = ... // an RDD of labeled points
- // The contingency table is constructed from the raw (feature, label) pairs and used to conduct
- // the independence test. Returns an array containing the ChiSquaredTestResult for every feature
- // against the label.
- ChiSqTestResult[] featureTestResults = Statistics.chiSqTest(obs.rdd());
- int i = 1;
- for (ChiSqTestResult result : featureTestResults) {
- System.out.println("Column " + i + ":");
- System.out.println(result); // summary of the test
- i++;
- }
- import java.util.Arrays;
- import org.apache.spark.api.java.JavaDoubleRDD;
- import org.apache.spark.api.java.JavaSparkContext;
- import org.apache.spark.mllib.stat.Statistics;
- import org.apache.spark.mllib.stat.test.KolmogorovSmirnovTestResult;
- JavaSparkContext jsc = ...JavaDoubleRDD data = jsc.parallelizeDoubles(Arrays.asList(0.2, 1.0, ...));
- KolmogorovSmirnovTestResult testResult = Statistics.kolmogorovSmirnovTest(data, "norm", 0.0, 1.0);
- // summary of the test including the p-value, test statistic,
- // and null hypothesis
- // if our p-value indicates significance, we can reject the null hypothesis
- System.out.println(testResult);
- import org.apache.spark.SparkContext;
- import org.apache.spark.api.JavaDoubleRDD;
- import static org.apache.spark.mllib.random.RandomRDDs.*;
- JavaSparkContext jsc = ...
- // Generate a random double RDD that contains 1 million i.i.d. values drawn from the
- // standard normal distribution `N(0, 1)`, evenly distributed in 10 partitions.
- JavaDoubleRDD u = normalJavaRDD(jsc, 1000000L, 10);
- // Apply a transform to get a random double RDD following `N(1, 4)`.
- JavaDoubleRDD v = u.map(
- new Function<Double, Double>() {
- public Double call(Double x) {
- return 1.0 + 2.0 * x;
- }
- });
- import org.apache.spark.mllib.stat.KernelDensity;
- import org.apache.spark.rdd.RDD;
- RDD<Double> data = ... // an RDD of sample data
- // Construct the density estimator with the sample data and a standard deviation for the Gaussian
- // kernels
- KernelDensity kd = new KernelDensity()
- .setSample(data)
- .setBandwidth(3.0);
- // Find density estimates for the given values
- double[] densities = kd.estimate(new double[] {-1.0, 2.0, 5.0});
二、MLlib统计指标之关联/抽样/汇总的更多相关文章
- mybatis实战教程二:多对一关联查询(一对多)
多对一关联查询 一.数据库关系.article表和user表示多对一的关系 CREATE TABLE `article` ( `id` ) NOT NULL AUTO_INCREMENT, `user ...
- QC学习二:QC使用中问题点汇总
QC 使用中问题点汇总,包括以下方面: 1.不兼容IE7,IE8的问题(服务器端设置) 2.无法在Win 7下正常下载页面(客户端设置) 3.在QC中填写中文内容后无法正常提交到数据库(客户端设置) ...
- Jmeter(二十五)_Xpath关联
在Jmeter中,除了正则表达式可以用作关联,还有一种方式也可以做关联,那就是 XPath Extractor.它是利用xpath提取出关键信息,传递变量. 具体用法 添加一个后置处理器-XPath ...
- Lua 学习之基础篇二<Lua 数据类型以及函数库 汇总>
引言 前面讲了运算符,这里主要对Lua的数据处理相关的数据类型和函数库进行总结归纳,后面会再接着单独分开讲解具体使用. 首先因为Lua 是动态类型语言,变量不要类型定义,只需要为变量赋值. 值可以存储 ...
- Android IOS WebRTC 音视频开发总结(二五)-- webrtc优秀资源汇总
本文主要整理一些webrtc相关资料供学习(会持续更新),转载请说明出处,文章来自博客园RTC.Blacker,欢迎关注微信公众号:blackerteam ---------------------- ...
- iOS二十种超酷时尚艺术滤镜汇总【附源码】
本文总结了20种ios滤镜都是基于GPUImage的,有3种滤镜是GPUImage库中包含的,还有17种是Instagram中的经典滤镜,集成在一个项目中.使用GPUImage可以非常容易创建我们自己 ...
- MyBatis学习(二)---数据表之间关联
想要了解MyBatis基础的朋友可以通过传送门: MyBatis学习(一)---配置文件,Mapper接口和动态SQL http://www.cnblogs.com/ghq120/p/8322302. ...
- ThinkPHP 关联模型(二十)
原文:ThinkPHP 关联模型(二十) ThinkPHP关联模型 两表关联查询:Message 和 user 关联条件uid(参考手册:模型->关联模型) 步骤: 一:创建Message表 ...
- SQLSERVER 使用 ROLLUP 汇总数据,实现分组统计,合计,小计
表结构: CREATE TABLE [dbo].[Students]( ,) NOT NULL, ) NULL, [Sex] [int] NOT NULL, ) NULL, ) NULL, , ) N ...
随机推荐
- 排序算法源码(JAVA)
public class Test { public static void main(String[] args){ Sort sort = new Sort(); sort.sortTest( ...
- openvpn server部署笔记
openvpn server 部署 1.准备 安装依赖 yum -y install gcc gcc-c++ openssl-devel openssl pam-devel 2.安装 lzo cd / ...
- Universal-Image-Loader 基本使用
简介 https://github.com/nostra13/Android-Universal-Image-Loader 项目的结构:每一个图片的加载和显示任务都运行在独立的线程中,除非这个图片缓存 ...
- CSS优先级总结(转载)
样式的优先级 多重样式(Multiple Styles):如果外部样式.内部样式和内联样式同时应用于同一个元素,就是使多重样式的情况. 一般情况下,优先级如下: (外部样式)External styl ...
- js接收复选框的值
<td><input type="checkbox" class="title" name="title" value=& ...
- .net中Web.config文件的基本原理及相关设置
11.7 使用web.config配置文件 Web配置文件web.config是Web 应用程序的数据设定文件,它是一份 XML 文件,内含 Web 应用程序相关设定的 XML 标记,可以用来简化 ...
- dp、sp 转换为 px 的工具类
public class DisplayUtil { /** * 将px值转换为dip或dp值,保证尺寸大小不变 * * @param pxValue (DisplayMetrics类中属性densi ...
- IO流+数据库课后习题
1,读取 试题文件 然后做题算分 File file1=new File("D:\\file","test.txt"); try{ FileReader in1 ...
- html5之web worker
Web Worker 在本文中 与 Web Worker 进行双向通信 WindowTimers 在 IE10 Platform Preview 4 中对 Web Worker 的更新 API 参 ...
- 细说PHP优化那些事
我们在用PHP编程的时候,总是想要使自己的程序占用资源最小,运行速度更快,代码量更少.往往我们在追求这些的同时却失去了很多东西.下面我想讲讲我对PHP优化的理解.优化的目的是花最少的代价换来最快的运行 ...