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


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

    R语言H2o包的几个应用案例

         笔者寄语:受启发想了解H2o平台的一些R语言实现,网上已有一篇H2o的demo文件。笔者在这多贴一些案例,并且把自己实践的一些小例子贴出来。

         关于H2o平台长啥样,可以看H2o的官网,关于深度学习长啥样,可以看一些教程,比如ParallelR博客之中的解析

    下面主要是贴几个案例,让大家看看。

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

    Matt︱R语言调用深度学习架构系列引文

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

    R用户的福音︱TensorFlow:TensorFlow的R接口




    碎片︱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系统下没有能够下载到该数据,所以后续的分析都没有办法继续进行了。

    [plain] view plain copy
     
     print?在CODE上查看代码片派生到我的代码片
    1. library(h2o)  
    2. # single thread  
    3. h2o.init()  
    4. #连接h2o平台  
    5.   
    6.   
    7. train_file <- "https://h2o-public-test-data.s3.amazonaws.com/bigdata/laptop/mnist/train.csv.gz"  
    8. test_file <- "https://h2o-public-test-data.s3.amazonaws.com/bigdata/laptop/mnist/test.csv.gz"  
    9.   
    10. train <- h2o.importFile(train_file)  
    11. test  <- h2o.importFile(test_file)  
    12.   
    13. # To see a brief summary of the data, run the following command  
    14. summary(train)  
    15. summary(test)  
    16.   
    17. y <- "C785"  
    18. x <- setdiff(names(train), y)  
    19.   
    20. # We encode the response column as categorical for multinomial  
    21. #classification  
    22. train[,y] <- as.factor(train[,y])  
    23. test[,y]  <- as.factor(test[,y])  
    24.   
    25. # Train a Deep Learning model and valid  
    26. system.time(  
    27.   model_cv <- h2o.deeplearning(x = x,  
    28.                                y = y,  
    29.                                training_frame = train,  
    30.                                distribution = "multinomial",  
    31.                                activation = "Rectifier",  
    32.                                hidden = c(32),  
    33.                                l1 = 1e-5,  
    34.                                epochs = 200)  
    35. )  

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

     

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

    [plain] view plain copy
     
     print?在CODE上查看代码片派生到我的代码片
    1. ##参考来自:h2o官方手册,h2o.deeplearning函数的示例  
    2. library(h2o)  
    3. h2o.init()  
    4. iris.hex <- as.h2o(iris)  
    5.   
    6. iris.dl <- h2o.deeplearning(x = 1:4, y = 6, training_frame = iris.hex)  #模型拟合  
    7. # now make a prediction  
    8. predictions <- h2o.predict(iris.dl, iris.hex)          #预测  
    9. as.data.frame(predictions)                             #预测数据变成数据框  
    10.   
    11. performance = h2o.performance(model = iris.dl)  
    12. print(performance)  
    输出的结果长成下面这个样子。

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

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

    [plain] view plain copy
     
     print?在CODE上查看代码片派生到我的代码片
    1. > print(performance)  
    2. H2OBinomialMetrics: deeplearning  
    3. ** Reported on training data. **  
    4. Description: Metrics reported on full training frame  
    5.   
    6. MSE:  0.01030833  
    7. R^2:  0.9536125  
    8. LogLoss:  0.05097025  
    9. AUC:  1  
    10. Gini:  1  
    11.   
    12. Confusion Matrix for F1-optimal threshold:  
    13.          0  1    Error    Rate  
    14. 0      100  0 0.000000  =0/100  
    15. 1        0 50 0.000000   =0/50  
    16. Totals 100 50 0.000000  =0/150  
    17.   
    18. Maximum Metrics: Maximum metrics at their respective thresholds  
    19.                       metric threshold    value idx  
    20. 1                     max f1  0.983179 1.000000  49  
    21. 2                     max f2  0.983179 1.000000  49  
    22. 3               max f0point5  0.983179 1.000000  49  
    23. 4               max accuracy  0.983179 1.000000  49  
    24. 5              max precision  0.999915 1.000000   0  
    25. 6                 max recall  0.983179 1.000000  49  
    26. 7            max specificity  0.999915 1.000000   0  
    27. 8           max absolute_MCC  0.983179 1.000000  49  
    28. 9 max min_per_class_accuracy  0.983179 1.000000  49  
    29.   
    30. Gains/Lift Table: Extract with `h2o.gainsLift(<model>, <data>)` or `h2o.gainsLift(<model>, valid=<T/F>, xval=<T/F>)`  


    每每以为攀得众山小,可、每每又切实

  • 相关阅读:
    js--在页面元素上(移动到或获取焦点)、鼠标离开(或失去焦点)
    Oracle 树操作、递归查询(select…start with…connect by…prior)
    oracle 错误码查看命令oerr ora及常用错误码总结--不断更新
    Dbvisual连接远程数据库报错Error Code: 17401
    struts2 转发、重定向概述
    javascript array操作
    理解 Node.js 里的 process.nextTick()
    js的in运算符与instanceof运算符
    Javascript引擎单线程机制及setTimeout执行原理说明
    NodeJS错误处理最佳实践
  • 原文地址:https://www.cnblogs.com/timssd/p/6416163.html
Copyright © 2020-2023  润新知