从零到一编写一个 spark 程序并提交到集群中运行

Spark Spark知识点 阅读详情

怎样用IDEA编写spark程序并提交到集群上运行

1.安装scala sdk

1.下载 scala 安装程序

#下载地址
https://www.scala-lang.org/download
#windwos 下安装
https://downloads.lightbend.com/scala/2.13.1/scala-2.13.1.msi

2.配置环境变量

  • 新增系统变量 SCALA_HOME

在这里插入图片描述

  • 配置PATH环境变量新增:%SCALA_HOME%\bin;

在这里插入图片描述

  • 配置CLASSPATH:
    在这里插入图片描述
  • 启动cmd:运行出现如下表示安装成功

在这里插入图片描述

2. IDEA 中的配置

1.安装scala插件

在这里插入图片描述
2. 创建 mave 项目

在这里插入图片描述
3.项目建好以后右键项目名称
在这里插入图片描述
3. 增加scala 框架的支持
在这里插入图片描述
4. 导入maven依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>cn.itcast</groupId>
    <artifactId>spark</artifactId>
    <version>0.1.0</version>

    <properties>
        <scala.version>2.11.8</scala.version>
        <spark.version>2.2.0</spark.version>
        <slf4j.version>1.7.16</slf4j.version>
        <log4j.version>1.2.17</log4j.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${scala.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_2.11</artifactId>
            <version>${spark.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-client</artifactId>
            <version>2.6.0</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j.version}</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <sourceDirectory>src/main/scala</sourceDirectory>
        <testSourceDirectory>src/test/scala</testSourceDirectory>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>

            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                        <configuration>
                            <args>
                                <arg>-dependencyfile</arg>
                                <arg>${project.build.directory}/.scala_dependencies</arg>
                            </args>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.1.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass></mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

5.选择scala sdk
在这里插入图片描述
6. 创建 scala工作目录
在这里插入图片描述

本地调试

  • 新建 worldcount.txt 文件写入一下内容

spark hello
hadoop hello
java hello
golang hello

def main(args: Array[String]): Unit = {
    // 1. 创建 Spark Context
    val conf = new SparkConf().setMaster("local[2]").setAppName("test")
    val sc: SparkContext = new SparkContext(conf)

    // 2. 读取文件并计算词频
    val source: RDD[String] = sc.textFile("e:/wordcount.txt", 2)
    val words: RDD[String] = source.flatMap { line => line.split(" ") }
    val wordsTuple: RDD[(String, Int)] = words.map { word => (word, 1) }
    val wordsCount: RDD[(String, Int)] = wordsTuple.reduceByKey { (x, y) => x + y }

    // 3. 查看执行结果
    wordsCount.foreach(println(_))
  }

运行结果

(spark,1)
(golang,1)
(hadoop,1)
(hello,4)
(java,1)

集群运行

1.将wordcount.txt 文件上传到 hdfs

hdfs dfs -put wordcount.txt /data

2.代码编写

def main(args: Array[String]): Unit = {
    // 1. 创建SparkContext
    val conf = new SparkConf().setAppName("word_count")
    val sc = new SparkContext(conf)

    // 2. 加载文件
    //     1. 准备文件
    //     2. 读取文件

    // RDD 特点:
    // 1. RDD是数据集
    // 2. RDD是编程模型
    // 3. RDD相互之间有依赖关系
    // 4. RDD是可以分区的
    val rdd1: RDD[String] = sc.textFile("hdfs:///data/wordcount.txt")

    // 3. 处理
    //     1. 把整句话拆分为多个单词
    val rdd2: RDD[String] = rdd1.flatMap(item => item.split(" ") )
    //     2. 把每个单词指定一个词频1
    val rdd3: RDD[(String, Int)] = rdd2.map(item => (item, 1) )
    //     3. 聚合
    val rdd4: RDD[(String, Int)] = rdd3.reduceByKey((curr, agg) => curr + agg )

    // 4. 得到结果
    val result: Array[(String, Int)] = rdd4.collect()
    result.foreach(item => println(item))
  }

3.spark-submit 命令

spark-submit [options] < app jar> < app options>
app jar 程序 Jar 包

  • app jar 程序 Jar 包
  • app options 程序 Main 方法传入的参数
  • options 提交应用的参数, 可以有如下选项

options 可选参数

参数解释
–master < url>同 Spark shell 的 Master, 可以是spark, yarn, mesos, kubernetes等 URL
–deploy-mode < client or cluster>Driver 运行位置, 可选 Client 和 Cluster, 分别对应运行在本地和集群(Worker)中
–class < class full name>Jar 中的 Class, 程序入口
–jars < dependencies path>依赖 Jar 包的位置
–driver-memory < memory size>Driver 程序运行所需要的内存, 默认 512M
–executor-memory < memory size>Executor 的内存大小, 默认 1G

4.提交到 Spark Standalone 集群中运行
1.打包
在这里插入图片描述
2.生成的jar包
在这里插入图片描述

3.进入安装 spark 安装目录 /bin 文件夹下执行脚本

cd /user/local/spark/bin

spark-submit --master spark://zhen:7077 \   #提交的主机
--class scl.MyRdd \   #包路径
/home/spark/original-lmspark-1.0-SNAPSHOT.jar  #要运行的jar包

4.观察后台管理页面可以看到任务正在运行

在这里插入图片描述

5.运行结果
在这里插入图片描述

结束

好了今天就讲到这里了,欢迎加我微信一起提升,如有帮助感谢赞赏。

在这里插入图片描述

编写Spark程序并提交到集群上运行 使用SCALA IDE, 編写Spark应用程序,提交到Spark集群上运行,最后查看结果 阅读详情

相关推荐

本地Spark程序提交到hadoop集群运行流程

1.本地环境准备 本文是将eclipse开发环境下的maven+Spark+scala程序移植到集群环境上执行过程,写的很粗糙,见谅。 本地用eclipse编写Spark小程序,完成从txt文件读取数据操作。 本地maven+Spark+scala环境就不多说了,如果配置出问题,就下载最新的eclipse然后从商店装插件吧。 注意在maven的配置文件pom.xml中插入Spark引用:

tf_dev的博客 3046

EduCoder-Java面向对象 -集合框架的实现代码(关卡一到关卡三)包括对问题的总结

我是小康小白,一个平平无奇的Java小白。热爱有趣的文字,生活和远方。 目录: 对实训题目考察的问题的总结 第一关 第一关答案 第二关 第二关答案 第三关 第三关答案 第四关 第四关答案 第五关 第五答案 第六关 第六关答案 对实训题目的总结 这次的实训题目不是很难,主要就是实践了常用集合的用法。其中有一点需要注意。与成员类中的封装属性一样 ArrayList的get方法只能或得对应的值,但不具备输出功能。如果想要输出应当用System.out.println

小康小白的博客 3995

Java Web提交任务到Spark Standalone集群并监控

Java Web提交任务到Spark Standalone集群并监控 环境 工程下载路径 Spark任务提交流程 问题及问题解决 后记Java Web提交任务到Spark Standalone集群并监控1. 环境 软件 版本 备注 IDEA 14.1.5 JDK 1.8 Spark 1.6.0 工程maven引用 Spark cdh5.7.3

fansy1990的专栏 6580

scala编写的Spark程序远程提交到服务器集群上运行

一.需要的软件: eclipse 相应版本的scalaIDE 与集群一样的spark安装包,主要是要用到spark中的jar包 与集群一样的hadoop安装包 与hadoop版本对应的winutil.exe,hadoop.dll(只要版本差距不大不一样也没关系) 二.步骤 (一)在eclipse中安装对应版本的ScalaIDE,具体安装见网上。(二)复制winutil.exe,hadoop.dll

1万+

Spark提交任务到集群

提交Spark程序到集群与提交MapReduce程序到集群一样,首先要将写好的Spark程序打成jar包,再在Spark-submit下通过命令提交。 Step1:打包程序         通说Intellij IDEA进行打包步骤: Step2:提交任务 ./spark-submit  --class DT --master spark:master:7077 --exe

蔡先生的专栏 4879

python程序如何提交到spark上运行_Spark基础:集群运行

往期链接:Spark基础:Spark SQL入门Spark基础:数据读写Spark基础:读写ParquetSpark基础:读写HiveSpark基础:读写JDBCSpark基础:Spark SQL优化Spark基础:分布式SQL查询引擎Spark基础:Hive特性兼容本篇简单介绍Spark如何在集群中运行,从而可以更好的理解各个组件的关系,会涉及到Driver、Executor、Job、...

weixin_39560245的博客 1058

Spark - 集群与本地提交Spark任务问题记录

Idea本地远程提交Spark任务,方便调试

大数据研究小白 1750

Spark任务提交

deploy-mode Driver 程序运行的地方,client 或者 cluster,默认是client。为了完成本关任务,你需要掌握:1.了解spark-submit的参数。./spark-submit --master 本地模式 --class 程序运行的主类名 xxx.jar。–master 提交到哪里执行,如 standalone,local,yarn,mesos等。–executor-memory 每个executor的内存,默认是1G。本关任务:学会将程序提交到集群上执行。

Junds0的博客 1183

使用idea开发Java的Wordcount程序并提交到spark集群运行

首先,我们需要确保集群已搭建好,win10安装idea,打开idea,选择创建maven项目 然后next,finish。 工程打开后再pom.xml中添加依赖,选择启动导入依赖 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" ...

菜鸟的博客 3741

使用idea编写spark程序并提交到yarn集群例子

需提前安装jdk、scala 1.创建新项目 2.增加Maven 3.修改pom.xml文件 &amp;amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;amp;gt; &amp;amp;lt;project xmlns=&amp;quot;http://maven.apache.org/POM/4

光于前裕于后的博客 4072

MATLAB下pdf文件操作读取示例

当遇到一些需要大量数据的项目,数据的读取与储存显得尤为重要。怎样把数据从其他格式的文件中读取,并运用到程序中是很多时候我们要解决的问题。对于平常的.txt,和.xlsx文件,MATLAB有对应的函数帮助读取,但是遇到pdf文件时MATLAB很难读取内容。本文以一个操作实例提供了一个从pdf文件中读取数据的方法。

UESTC 五高考3模拟的博客 6558

在spark-shell中运行代码 编写Spark独立应用程序 在集群上运行Spark应用程序

在spark-shell中运行代码 编写Spark独立应用程序 在集群上运行Spark应用程序

weixin_56814370的博客 3296

Oracle 11g版本下载及安装超详细教程图解

新手Oracle安装教程

weixin_43738344的博客 10万+

Spark 1分钟简洁集群搭建 并提交第一个新手程序

准备环境 安装JDK不需要安装Scala 上传spark安装包 解压spark并修改配置文件(两个配置文件,第一个配置文件添加了3个配置文件) 将配置好的spark安装程序拷贝给其他机器for i in {5…8}; do scp -r /bigdata/spark-2.2.0-bin-hadoop2.7/ node-$i:/bigdata; done 启动spark (s...

李昊轩的博客 2007

高杂合度基因组组装实战:Hifiasm参数调优与purge_dups过滤效果对比(附猪毛菜案例)

本文深入探讨了高杂合度基因组组装中Hifiasm参数调优与purge_dups过滤的实战效果对比,通过猪毛菜案例详细解析了两种方法的适用场景与优化策略。文章重点分析了purge_dups在contig过滤中的显著效果,为基因组组装提供了关键的技术参考。

weixin_29232121的博客 495

单点DToF激光测距传感器各家产品的比较

汇总DToF 单点测距传感器的相关信息

Linux 设备驱动概述及开发环境构建 (一) 1774

六十七、Spark-两种运行方式(本地运行,提交集群运行)

本地运行:在IDEA中直接运行控制台输出结果即可 集群运行:在本地将程序打包为 jar,提交至集群运行其程序(将结果上传至hdfs)

7705

手把手教你用QEMU虚拟化华为路由器固件(附完整网络配置指南)

本文提供了一份详尽的QEMU虚拟化华为路由器固件的实战指南。从固件解包、网络桥接配置到QEMU虚拟机启动,手把手教你搭建完整的嵌入式设备沙箱环境,特别适合安全研究、逆向分析和学习嵌入式系统工作原理。

tgb3456789的博客 937

idea中编写spark程序并打包到集群执行

本篇主要介绍了如何使用IDEA在本地打包Spark应用程序(以K-Means为例),并提交到集群执行。 1、 安装JDK与Scala SDK JDK和Scala SDK的安装在这里不再赘述,需要注意的是:要设置好环境变量,这样新建项目时就能自动检测到对应的版本,同时版本最好不要太高,以避免版本不兼容的问题,本篇采用的是JDK 8.0与Scala 2.10.6。 JDK下载地址:http://www.oracle.com/technetwork/java/javase/downloads/ Scala下载

hzp666的博客 3609

风电光伏功率预测竞赛精华总结:技术解析与实战经验

本文深度解析新能源功率预测竞赛的技术要点与实战经验。首先介绍了风电、光伏功率预测对电网调度优化、降低运营风险的重要性,以及多个竞赛的基本概况。在数据特征分析部分,详细探讨了气象预报数据和功率数据的特征,包括时间周期性、数据质量问题及处理方法。针对异常值检测、数据标准化和特征工程(如时间特征、统计聚合特征、风速风向特征和滞后特征)提供了具体的技术实现方案。文章为新能源功率预测提供了实用的技术指导,对相关竞赛和实际应用具有重要参考价值。

算法工程师 206

WebRTC之beamforming算法

CSND已永久停更,最新版唯一来源点击下面链接跳转: 语音增强和语音识别网页书 坐标问题 这里以笔记本为例进行说明,当笔记本按如下方式打开: 首先是键盘和液晶屏呈90度,然后鼠标上方,也就是液晶屏上方正中间是camera,把平行于键盘的面看成是xy平面,把液晶屏所在的面看成是xz平面,所有平面的原点都在Camera的位置。 方位角:从原点开始,Camera的右侧是0度,逆时针方...

shichaog的专栏 1万+

使用Scala编写第一个Spark程序

使用Scala编写第一个Spark工程演示目标演示环境创建Spark工程运行Spark工程本地运行Yarn-Cluster运行 演示目标 在Windows环境中使用Scala编写一个spark工程(WordCount),并分别使用“本地”三种方式运行。在开始之前,请确保HDFS与YARN环境已搭建完毕,可参考下列博文: 从0开始搭建Hadoop2.x高可用集群(HDFS篇) 从0开始搭建Hadoop2.x高可用集群(YARN篇) 演示环境 软件 备注 JDK jdk-8u211 Scal

NickZxing 6628

【重识云原生】第四章云网络4.9.5.1节下一代智能网卡——DPU综述

随着数据中心的高速发展,通信能力和计算能力成为数据中心基础设施的相辅相成的两个重要发展方向。若数据中心仅关注计算能力的提升,通信基础设施的提升跟不上,那么数据中心的整体系统性能依然受限,无法发挥出真正的潜力。DPU的提出背景就是应对这些数据量和复杂性的指数级增长。未来,需要将计算移至接近数据的位置,这是目前业界所公认的以数据为中心的体系结构下的创新。综上,DPU对数据中心来说,是通过更明细的分工来实现效率的提升、实现总体系统的成本最优化。...

junbaozi的专栏 1725

spark程序提交到集群上_Spark集群模式&Spark程序提交

Spark集群模式&Spark程序提交1. 集群管理器Spark当前支持三种集群管理方式Standalone—Spark自带的一种集群管理方式,易于构建集群。Apache Mesos—通用的集群管理,可以在其上运行Hadoop MapReduce和一些服务应用。Hadoop YARN—Hadoop2中的资源管理器。Tip1: 在集群不是特别大,并且没有mapReduce和Spark同时运行...

weixin_35437039的博客 1468

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

深度学习工具包 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 程序开发与提交:本地与集群模式全解析

本文将深入探讨 Spark 程序在本地开发并远程提交到集群测试的过程,以及使用 spark - submit 脚本在集群模式下提交程序的相关知识,包括参数配置、运行模式等内容。

天冬忘忧的博客 1935

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

上一篇: 大数据应用-Spark集群的部署
下一篇: docker部署mysql
精诚所至金石为开
博客等级 码龄8年 12粉丝 29原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值