前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >R语言︱H2o深度学习的一些R语言实践——H2o包

R语言︱H2o深度学习的一些R语言实践——H2o包

作者头像
悟乙己
发布2019-05-28 08:24:26
2.7K0
发布2019-05-28 08:24:26
举报
文章被收录于专栏:素质云笔记

碎片︱R语言与深度学习

sparklyr包:实现Spark与R的接口,会用dplyr就能玩Spark

—————————————————————————————————————

本文中介绍的H2o包在调用的过程主要有以下简要步骤

连接、搭建H2o环境(heo.init())——数据转换成h2o格式(as.h2o)——模型拟合(h2o.deeplearning)——预测(h2o.predict)——数据呈现(h2o.performance)。

一、H2o包的demo(glm)

网上已经有了,博客笔者看了并做了简单的中文注释。详情可以见std1984博客

二、来自ParallelR博客的案例

博客中主要是为了说明深度学习要比其他普通学习方法的精度高。数据是H2o网站数据,笔者windows系统下没有能够下载到该数据,所以后续的分析都没有办法继续进行了。

代码语言:javascript
复制
library(h2o)
# single thread
h2o.init()
#连接h2o平台


train_file <- "https://h2o-public-test-data.s3.amazonaws.com/bigdata/laptop/mnist/train.csv.gz"
test_file <- "https://h2o-public-test-data.s3.amazonaws.com/bigdata/laptop/mnist/test.csv.gz"

train <- h2o.importFile(train_file)
test  <- h2o.importFile(test_file)

# To see a brief summary of the data, run the following command
summary(train)
summary(test)

y <- "C785"
x <- setdiff(names(train), y)

# We encode the response column as categorical for multinomial
#classification
train[,y] <- as.factor(train[,y])
test[,y]  <- as.factor(test[,y])

# Train a Deep Learning model and valid
system.time(
  model_cv <- h2o.deeplearning(x = x,
                               y = y,
                               training_frame = train,
                               distribution = "multinomial",
                               activation = "Rectifier",
                               hidden = c(32),
                               l1 = 1e-5,
                               epochs = 200)
)

三、最简单的案例——基于iris数据集的深度学习

本案例主要来自h2o官方手册中,h2o.deeplearning包的示例,比较简单易懂。如果你想看预测的数据可以用as.data.frame来变成R能识别的数据框格式。

代码语言:javascript
复制
##参考来自:h2o官方手册,h2o.deeplearning函数的示例
library(h2o)
h2o.init()
iris.hex <- as.h2o(iris)

iris.dl <- h2o.deeplearning(x = 1:4, y = 6, training_frame = iris.hex)  #模型拟合
# now make a prediction
predictions <- h2o.predict(iris.dl, iris.hex)          #预测
as.data.frame(predictions)                             #预测数据变成数据框

performance = h2o.performance(model = iris.dl)
print(performance)

输出的结果长成下面这个样子。

大概构成是:模型评价指标+混淆矩阵+一些指标的阈值(这个是啥??)

看到混淆矩阵,你就差不多懂了~

代码语言:javascript
复制
> print(performance)
H2OBinomialMetrics: deeplearning
** Reported on training data. **
Description: Metrics reported on full training frame

MSE:  0.01030833
R^2:  0.9536125
LogLoss:  0.05097025
AUC:  1
Gini:  1

Confusion Matrix for F1-optimal threshold:
         0  1    Error    Rate
0      100  0 0.000000  =0/100
1        0 50 0.000000   =0/50
Totals 100 50 0.000000  =0/150

Maximum Metrics: Maximum metrics at their respective thresholds
                      metric threshold    value idx
1                     max f1  0.983179 1.000000  49
2                     max f2  0.983179 1.000000  49
3               max f0point5  0.983179 1.000000  49
4               max accuracy  0.983179 1.000000  49
5              max precision  0.999915 1.000000   0
6                 max recall  0.983179 1.000000  49
7            max specificity  0.999915 1.000000   0
8           max absolute_MCC  0.983179 1.000000  49
9 max min_per_class_accuracy  0.983179 1.000000  49

Gains/Lift Table: Extract with `h2o.gainsLift(<model>, <data>)` or `h2o.gainsLift(<model>, valid=<T/F>, xval=<T/F>)`

———————————————————————————

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016年04月22日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 碎片︱R语言与深度学习
  • 一、H2o包的demo(glm)
  • 二、来自ParallelR博客的案例
  • 三、最简单的案例——基于iris数据集的深度学习
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档