如何用R语言做深度学习

1 如何用R语言做深度学习?

如何用R语言做深度学习?

阅读本文,你可以获得:

  • R语言做深度学习工作环境创建
  • R语言快速实现神经网络模型
  • R语言做深度学习的资料
  • 深度学习的应用场景

感谢RStudio公司开发的keras包,使得R语言可以利用keras深度学习框架来做深度学习,具有简洁,易学,好用等特性。

什么是Keras?

Keras是基于Python的深度学习库。

Keras 是一个用 Python 编写的高级神经网络API,它能够以TensorFlow, CNTK, 或者Theano作为后端运行。Keras 的开发重点是支持快速的实验,能够以最短的时间把你的想法转化为实验结果,是做研究的好帮手。

谈及Kears深度学习库,就必须要介绍他的作者François Chollet和一本经典的书籍《Deep Learning With Python》

Francois Chollet在谷歌从事深度学习方面的工作。他是Keras深度学习库的创建者,也是TensorFlow机器学习框架的贡献者。他还从事深度学习研究,重点研究计算机视觉和机器学习在形式推理中的应用。他的论文曾在计算机视觉与模式识别(CVPR)、神经信息处理系统(NIPS)和学习代表国际会议等领域的重要会议上发表。

作者的介绍翻译自他写的书籍《Deep Learning With Python》。

《Deep Learning With Python》这本书使用Python语言和强大的Keras库带您进入深度学习领域。 本书由Keras创建者和Google AI研究员FrançoisChollet撰写,通过直观的解释和实际的例子帮助您构建对深度学习的理解。您将在计算机视觉,自然语言处理和生成模型中应用和实践。当您学习和实践完这本书里面的内容,您将拥有在您自己的项目中应用深度学习的知识和实践技能。

若是您想学习使用Python语言和Keras库做深度学习,毫无疑问,推荐您阅读这本书籍。若是您是Python和R的双面手,阅读这本书,对于您利用R语言做深度学习也非常有帮助和启发。

什么是keras包?

它是RStudio公司开发一个R包,是Keras深度学习框架的R语言接口,利用这个包,就可以在R平台上面编写代码,使用这个高级的神经网络API。Keras的开发重点是实现快速实验,支持基于卷积的网络和循环网络(以及两者的组合),并在CPU和GPU设备上无缝运行。

如何用R语言做深度学习?

首先,构建和配置R语言做深度学习的工作环境

  • 第一步,下载和安装Anaconda软件。
  • 第二步,创建r-tensorflow环境
  • 第三步,在r-tensorflow环境下,安装tensorflow库和keras库
  • 第四步,测试tensorflow库和keras库能否正常工作。
  • 第五步,安装keras包

下载Anaconda软件的网址:

https://www.anaconda.com/download/

创建r-tensorflow环境的命令:

打开Anaconda Prompt,执行命令

conda create--name r-tensorflow python=3.6

进入到r-tensorflow环境,执行命令

activater-tensorflow

安装tensorflow库和keras库

conda installtensorflow

conda installkeras

测试tensorflow库和keras库是否安装成功,测试代码

import tensorflow astf

import keras

print(tf.__version__)

print(keras.__version__)

打开RStudio,安装keras包

install.packages( 'keras')

keras包安装完后,测试是否可以使用,加载keras包

library(keras)

其次,R语言做深度学习的工作环境弄好后,就可以利用R语言做深度学习了。

深度学习是常用架构时神经网络,R平台下基于keras包对接Keras深度学习框架轻松快捷实现一个神经网络模型,参考代码

# R包

library(keras)

library(tidyverse)

mnist <- dataset_mnist()

str(mnist)

train_images <- mnist $train$x

train_label <- mnist $train$y

test_images <- mnist $test$x

test_label <- mnist $test$y

dim(train_images)

dim(test_images)

dim(train_label)

dim(test_label)

str(train_images)

glimpse(train_images)

str(test_images)

# 设计神经网络结构

network <- keras_model_sequential() %>%

layer_dense(units = 512, activation = "relu", input_shape = c(28 * 28)) %>%

layer_dense(units = 10, activation = "softmax")

# 设计算法的损失函数,优化算法和度量准则

network %>% compile(

optimizer = "rmsprop",

loss = "categorical_crossentropy",

metrics = c( "accuracy")

)

# 数据处理

train_images <- array_reshape(train_images, c(60000, 28 * 28))

train_images <- train_images / 255

test_images <- array_reshape(test_images, c(10000, 28 * 28))

test_images <- test_images / 255

train_labels <- to_categorical(train_label)

test_labels <- to_categorical(test_label)

dim(train_images)

dim(test_images)

dim(train_labels)

dim(test_labels)

# 训练数据集上拟合模型

network %>% fit(train_images, train_labels, epochs = 5, batch_size = 128)

# 测试数据集

metrics <- network %>% evaluate(test_images, test_labels)

metrics

# 测试样本的前10个样本的类别预测

network %>% predict_classes(test_images[1:10, ])

最后,就是选择感兴趣的领域,快速学习和实验R平台和深度学习实现想法和解决问题。

R语言做深度学习好资料

概而言之,一本书,一份代码,一个PPT。

一本书《Deep Learning With R》,它是François Chollet和JJ Allaire合作写的。

阅读完这本书,掌握和理解书本介绍的内容,并且利用R平台和keras包完成相应的实验,可以让你掌握R平台做深度学习的知识和技能,能够迁移到您的实际问题和应用场景。

一份代码是指这本书配套的代码,包括代码的Rmd文件和配套生成的html文件,从github克隆一份代码,执行如下命令。

gitclone https://github.com/jjallaire/deep-learning-with-r-notebooks.git

结合书籍和代码一起学习,可以让你从理论和实践掌握R语言做深度学习。

一个PPT是RStudio2019大会上Rick Scavetta讲解的《Introduction to

Deep Learning with R and keras》,PPT的链接:

http://scavetta.academy/DLwR/Presentation/SCAVETTA%2C%20Rick%20--%20Intro%20to%20Deep%20Learning%20--%20RStudioConf2019.pdf

这个讲解对应的github链接:

https://github.com/Scavetta/conf_tensorflow_training_day1

您可以下载PPT和对应的Code,一起学习和实践。

这份PPT的提纲。

深度学习的关键算法(工业界常用算法)做了介绍和R平台下keras包实现的演示。

深度学习应用场景

深度学习有着广泛地应用,在自然语言处理,图像识别,语音识别,对话系统,机器翻译等领域取得显著成果。

结合已有成果和实际问题,容易发现深度学习的典型应用场景,有以下几点。(罗列在此,欢迎补充)

  • 特征的自学习和表示,这是深度学习的一大优势,可以避免手工设计特征的繁琐,耗时和低效,利用深度学习算法,可以对所研究的对象进行更高层次的抽象和表示,而这种表示和抽象可以当做隐性的特征集送入到合适的模型进行学习。
  • 计算机视觉的应用,不管是图像的分类,还是目标的检测,还是看图说话等,深度学习可以发挥其作用,以取的可接受的效果和可应用的价值。
  • 自然语言处理领域,不管是文本的分析,还是文本深度语义挖掘,还是文本的生成等,深度学习也有用武之地,这方面的论文和产品,可以轻易发现。
  • 深度学习的跨界融合,利用深度学习这个工具和方法,解决不同行业里面的实际问题,比方说,深度学习在无线网络中的应用;深度学习金融反欺诈中的应用;深度学习在电子商务的推荐系统中应用;深度学习在银行的智能客服中的应用等等。

关于深度学习的应用场景,还有很多,包括已有的,或者将来会出现的。选择自己感兴趣的领域,持续地关注,跟踪和实践,同时,培养和形成跨界的思维,举一反三,触类旁通,让深度学习技术更好地解决实际问题,以创造价值。

参考:

https://www.sohu.com/a/291416620_274950

  • 5
    点赞
  • 56
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Thank you for purchasing the MEAP for Deep Learning with R. If you are looking for a resource to learn about deep learning from scratch and to quickly become able to use this knowledge to solve real-world problems, you have found the right book. Deep Learning with R is meant for statisticians, analysts, engineers and students with a reasonable amount of R experience, but no significant knowledge of machine learning and deep learning. This book is an adaptation of my previously published Deep Learning with Python, with all of the code examples using the R interface to Keras. The goal of the book is to provide a learning resource for the R community that goes all the way from basic theory to advanced practical applications. Deep learning is an immensely rich subfield of machine learning, with powerful applications ranging from machine perception to natural language processing, all the way up to creative AI. Yet, its core concepts are in fact very simple. Deep learning is often presented as shrouded in a certain mystique, with references to algorithms that “work like the brain”, that “think” or “understand”. Reality is however quite far from this science- fiction dream, and I will do my best in these pages to dispel these illusions. I believe that there are no difficult ideas in deep learning, and that’s why I started this book, based on premise that all of the important concepts and applications in this field could be taught to anyone, with very few prerequisites. This book is structured around a series of practical code examples, demonstrating on real- world problems every the notions that gets introduced. I strongly believe in the value of teaching using concrete examples, anchoring theoretical ideas into actual results and tangible code patterns. These examples all rely on Keras, the deep learning library. When I released the initial version of Keras almost two years ago, little did I know that it would quickly skyrocket to become one of the most widely used deep l

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值