Spark经典案例5-求最大最小值

Spark经典案例之求平均值,最大最小值,求top值,非结构数据处理,统计每天新增用户数 1、需求分析 对输入文件中数据进行就算学生平均成绩。输入文件中的每行内容均为一个学生的姓名和他相应的成绩,如果有多门学科,则每门学科为一个文件。 要求在输出中每行有两个间隔的数据,其中,第一个代表学生的姓名,第二个代表其平均成绩。 2、原始数据 1)math: 张三,88 李四,99 王五,66 赵六,77 2)china: 张三,78 李四,89 王五,96 赵六,67 3)english: 张三,80 李四,82 王五,84 赵六,86 样本输出: 张三,82 李四,90 王五,82 赵六,76 阅读详情

数据准备
eightteen_a.txt
102
10
39
109
200
11
3
90
28

eightteen_b.txt
5
2
30
838
10005

package ClassicCase

import org.apache.spark.{SparkConf, SparkContext}

/**
  * 业务场景:求最大最小值
  * Created by YJ on 2017/2/8.
  */


object case5 {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local").setAppName("reduce")
    val sc = new SparkContext(conf)
    sc.setLogLevel("ERROR")
    val fifth = sc.textFile("hdfs://192.168.109.130:8020//user/flume/ClassicCase/case5/*", 2)
    val res = fifth.filter(_.trim().length>0).map(line => ("key",line.trim.toInt)).groupByKey().map(x => {
      var min = Integer.MAX_VALUE
      var max = Integer.MIN_VALUE
      for(num <- x._2){
        if(num>max){
          max = num
        }
        if(num<min){
          min = num
        }
      }
      (max,min)
    }).collect.foreach(x => {
      println("max\t"+x._1)
      println("min\t"+x._2)
    })
  }

}

结果输出
max 10005
min 2

SparkDataFrame求某一列的最大值和最小值和求和 1.利用Scala 沟边 import spark.implicits._ var data1 = Seq( ("0", "2002", "196", "1", "bai"), ("1", "4004", "192", "2", "wang"), ("0", "7007", "95", "3", "wang"), ("0", "4004", "4", "4", "wang")... 阅读详情

相关推荐

Spark 分层抽样与求最大值最小值

详见注释 package com.beagledata.sparkimport org.apache.spark.{SparkConf, SparkContext}/** * 分层抽样 * * Created by drguo on 2017/8/21. * blog.youkuaiyun.com/dr_guo */object PCSStratifiedSampling { val c

光于前裕于后的博客 3655

Spark 求最大值最小值

SPARK求最大值最小值 def maxMinValues: RDD[(Int,Int)] ={ val sc = SparkUtil.sparkLocal() sc.setLogLevel("DEBUG") val data = sc.textFile("",1) val num =data.flatMap{line=> line.split(",") }.filter(x=>x.trim().length>0).map(x=&gt

neo_lcx的博客 2045

相机图像质量研究(15)常见问题总结:光学结构对成像的影响--暗角

老式相机的暗角往往比较明显,周围一圈能够明显感觉到亮度下降的很多,当然有些电源模仿手持相机的摄影效果,也能看到周围明显的亮度下降。一、

xiaoshixiu的专栏 1124

Spark 求最大值和最小值

代码: import org.apache.spark.{SparkConf, SparkContext} import scala.util.Random object MaxAndMin extends App { System.setProperty("hadoop.home.dir","D:\\soft\\hadoop\\hadoop-2.7.3") val conf=new SparkConf().setMaster("local[*]").setAppName("MaxAndM

star5610的博客 2402

OpenLayers源码解析1 Map.js

Map.js 父类:./PluggableMap/PluggableMap 引用:5个模块 ./renderer/Composite.js ./PluggableMap.js ./obj.js ./control.js(控件) ./interaction.js(交互) 主要功能:核心组件,渲染地图 必要参数: view layers target controls和interactions要是未指定,使用默认值 方法:createRenderer()? /** * @module ol/Map */ i

qq_45005996的博客 1898

EDSR-PyTorch实战:从模型下载到超分辨率图像生成

本文详细介绍了如何使用PyTorch实现EDSR模型进行超分辨率图像生成,包括环境配置、模型下载、参数调优及常见问题解决方案。EDSR作为超分辨率重建的利器,通过深度残差网络显著提升图像质量,特别适合老照片修复等场景。文章还提供了视频处理和自定义训练的进阶技巧,帮助开发者快速掌握这一技术。

weixin_29046035的博客 457

7道RDD编程练习题

公众号后台回复关键字:pyspark,获取本项目github地址。为强化RDD编程API的使用经验,现提供一些小练习题。读者可以使用RDD的编程API完成这些小练习题,并输出结果。这些练...

Python_Ai_Road的博客 2995

从零到精通:ROS2 MoveIt2与MPC机械臂轨迹规划的完整配置流程

本文详细介绍了ROS2 MoveIt2与MPC机械臂轨迹规划的完整配置流程,从环境准备到高级功能扩展,帮助开发者实现精准控制。通过集成模型预测控制(MPC),机械臂能够优化复杂轨迹规划,处理动态避障,提升工业自动化效率。

juice的博客 706

Hadoop经典案例Spark实现(五)——求最大最小值问题

Hadoop经典案例Spark实现(五)——求最大最小值问题,同时在一个任务中求出来。

Ganymede的Hadoop世界 7086

MAX31865三线PT100测温实战:配置、接线与代码全解析

本文详细解析MAX31865三线PT100测温的配置、接线与代码实现。通过实战经验分享,介绍如何利用MAX31865芯片实现高精度温度测量,重点讲解三线制接法的自动误差补偿功能,并提供完整的寄存器配置、SPI通信和温度转换算法,帮助开发者快速解决工业测温中的常见问题。

ss78901的博客 757

Chromatix_AEC—深入解析曝光表配置与传感器参数计算

本文深入解析高通Chromatix AEC模块中的曝光表配置与传感器参数计算,详细介绍了自动曝光控制(AEC)的核心概念、首行曝光时间计算、行时间与曝光模式对比、帧率计算逻辑以及曝光表高级配置技巧。通过实战案例展示如何优化传感器参数联调,帮助开发者掌握Chromatix工具在摄像头系统中的关键应用。

266

List集合排序找出其中的最大和最小值

本文主要讲述对list进行排序的几种方式以及找出list中的最大值和最小值。

ratel的博客 1万+

SI案例分享--FPC(柔性电路板)信号仿真

设计高性能的柔性PCB时,由于采用了网格地的参考面构造,因此,需要按照特定的结构进行布局,才可以保证所需目标阻抗的稳定性,该结构的配置过程称为“Hatch Configuration”,合理的参数配置将有助于得到满意的设计效果。

一只豌豆象的博客 2827

Spark经典案之求最大最小值

数据准备 eightteen_a.txt 102 10 39 109 200 11 3 90 28 eightteen_b.txt 5 2 30 838 10005 package ClassicCase import org.apache.spark.{SparkConf, SparkContext} /** * 业务场景:求最大最小值 * Created by YJ on 2...

zhangMY12138的博客 1400

做了一个3DTiles编辑器,支持3DTiles的预览和裁剪导出

3DTiles编辑器的功能极其简洁,核心就是3DTiles格式模型的预览和裁剪。为了演示方便,本文所使用的源数据为mipmap3d[1]网站所提供的无人机拍摄影像,并进行3DTiles构建。打开软件,输入的绝对路径之后,点击添加模型,就可以将模型加载进预览区。之后,点击裁剪模式按钮,默认会出现立方体裁剪框,可通过拖动句柄的方式去调整裁剪框的范围。同时,除了默认的盒体裁切模式外,还支持多边形裁切,点击多边形裁切后,可切换到顶视图,选择重绘多边形,可进行打点绘制。

兴趣使然的创作者 601

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Spark编程经典综合案例

1. 求TOP值 2. 求最大值最小值 3. 文件排序 4. 二次排序 5. 连接操作 1. WordCount程序解析

MusicDancing的博客 3464

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

Spark GraphX——pregel案例:求最短路径、求最小值

一、Pregel API def pregel[A] (initialMsg: A, maxIter: Int = Int.MaxValue, activeDir: EdgeDirection = EdgeDirection.Out) (vprog: (VertexId, VD, A) => VD, sendMsg: EdgeTriplet[VD, ED] => Iterator[(VertexId, A)], mergeMsg: (A, A) =&gt

Messi的小迷弟 1432

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

python求最大值最小值平均值_pyspark计算最大值、最小值、平均值

需求:使用pyspark计算相同key的最大值、最小值、平均值说明: 最大值和最小值好计算,直接reduceByKey后使用python内置的max、min方法平均值计算提供两种计算方法,直接先上代码和运行结果,后面有代码记录def main():sc = SparkContext(conf=SparkConf())rdd1 = sc.parallelize([("a", 3), ("a", 2)...

weixin_39966465的博客 3775

Spark 常用案例

数据过滤清洗数据 //textFile() 加载数据 val data = sc.textFile("/spark/seven.txt") //filter 过滤长度小于0, 过滤不包含GET与POST的URL val filtered = data.filter(_.length() &gt; 0).filter(line =&gt; (line.indexOf...

IamGaoYue 7415

【Spark入门项目】统计男女生身高的平均值、最大、最小值

项目要求 分别统计男女生身高的平均值、最大、最小值,数据格式为(ID,sex,height),如下: 1 M 174 2 F 165 3 M 180 4 M 176 5 F 160 6 M 188 7 F 170 流程 初始化spark配置 通过textFile方法读取身高数据文件 RDD的每一个元素为txt文件中的一行,通过map方法返回K-V对,key为该行数据的性别,value为该行的身高 通过filter函数过滤分别得到男生、女生的身高heightsFemale和heightsMale 为了求

这个人很蓝 3395

Spark求数据的统计值:最大值、最小值、平均值、方差、数量(Java代码)

Spark计算统计值用到的核心类Java代码注 用到的核心类 org.apache.spark.mllib.stat.Statistics org.apache.spark.mllib.stat.MultivariateStatisticalSummary Java代码 package ml.summary; import org.apache.spark.SparkConf; import org.apache.spark.api.java.JavaRDD; import org.apache.spar

wendaocp的博客 4156

Spark编程-使用SparkCore求TopN,Max_Min_Value

本文主要使用SparkCore求top5值编程,博客中有响应数据,并且对于求最大最小值给了两种求法。

Matrix70的博客 929

Spark 算法练习两则

练习一:求最大最小值 在文件中获取数据求浮点数和整数的最大值和最小值 1,2.33,4,1.55,2.56, 55,55,55,23.77,1.88987,0.3324, 22.567,5.5567,7.8895,33 import org.apache.spark.{SparkConf, SparkContext} object demo01 { def main(args: Arra...

将懒惰进行到底 678

[Spark Core] Spark 实现气温统计

0. 说明   聚合气温数据,聚合出 MAX 、 MIN 、 AVG 1. Spark Shell 实现   1.1 MAX   分步实现 # 加载文档 val rdd1 = sc.textFile("file:///home/centos/temp3.dat") # 压扁 val rdd2 = rdd1.map(line=>{var arr = ...

weixin_33856370的博客 821

spark编程基础--5.4综合实例

.案例1:求TOP值1 案 //TopN.scala import org.apache.spark.{SparkConf, SparkContext} object TopN { def main(args: Array[String]): Unit = { val conf = new SparkConf().setAppName("TopN").setMaster("local") val sc = new SparkContext(conf) sc.setLog.

欢迎来到我的博客 2268
上一篇: Spark经典案例4-求平局值
下一篇: Spark经典案例6-求top值
yjgithub
博客等级 码龄11年 53粉丝 105原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值