之前知道h2o是一个深度学习的框架,类似于tensorflow之类的深度学习框架。但是知道h2o的人不是那么多,然后最近在学习如何部署模型,发现h2o还是一个机器学习的平台,利用h2o能够很好的部署模型。
稍微介绍一下,h2o是一家AI公司(h2o.AI)的一个产品,
image.png
他们公司的网址如下:https://www.h2o.ai/
他们公司还有一下其他机器学习的产品。这里主要讲h2o,以及如何很好的应用与工作中。
wiki 的介绍:
H2O项目旨在为云计算开发分析界面,为用户提供数据分析工具。[1]该软件是开源的,免费分发。该公司收取提供客户服务和定制扩展的费用。
大数据集太大,无法使用R等传统软件进行分析。H2O软件提供适用于大数据的数据结构和方法。H2O允许用户分析和可视化整套数据,而不使用Procrustean策略,即仅使用传统统计软件包研究一小部分。[2] H2O的统计算法包括K均值聚类,广义线性模型,分布式随机森林,梯度增强机,朴素贝叶斯,主成分分析和广义低秩模型。[6]
介绍一个例子
利用机器学习中比较常用的iris数据集
> library(h2o) > h2o.init(nthreads = -1) # 初始化 Connection successful! R is connected to the H2O cluster: H2O cluster uptime: 2 days 12 hours H2O cluster timezone: Asia/Shanghai H2O data parsing timezone: UTC H2O cluster version: 3.20.0.8 H2O cluster version age: 9 days H2O cluster name: H2O_started_from_R_milin_sig066 H2O cluster total nodes: 1 H2O cluster total memory: 1.99 GB H2O cluster total cores: 4 H2O cluster allowed cores: 4 H2O cluster healthy: TRUE H2O Connection ip: localhost H2O Connection port: 54321 H2O Connection proxy: NA H2O Internal Security: FALSE H2O API Extensions: XGBoost, Algos, AutoML, Core V3, Core V4 R Version: R version 3.4.3 (2017-11-30) > iris.h2o <- as.h2o(iris) # 将数据转成h2o格式 |========================================================| 100% > y <- names(iris.h2o)[5] # 选出因变量> x <- setdiff(names(iris.h2o),y) # 选出自变量> part <- h2o.splitFrame(iris.h2o,0.8) # 划分数据集合> train <- part[[1]] # 训练集合> test <- part[[2]] # 测试集合> > m <- h2o.deeplearning(x,y,iris.h2o) |========================================================| 100% > m Model Details:==============H2OMultinomialModel: deeplearning Model ID: DeepLearning_model_R_1538107989583_22 Status of Neuron Layers: predicting Species, 3-class classification, multinomial distribution, CrossEntropy loss, 41,803 weights/biases, 498.2 KB, 1,500 training samples, mini-batch size 1 layer units type dropout l1 l2 mean_rate1 1 4 Input 0.00 % NA NA NA2 2 200 Rectifier 0.00 % 0.000000 0.000000 0.0037963 3 200 Rectifier 0.00 % 0.000000 0.000000 0.0157974 4 3 Softmax NA 0.000000 0.000000 0.012824 rate_rms momentum mean_weight weight_rms mean_bias bias_rms1 NA NA NA NA NA NA2 0.003129 0.000000 0.000194 0.105557 0.484837 0.0122743 0.046676 0.000000 -0.000892 0.070076 0.998739 0.0048224 0.090778 0.000000 -0.016230 0.394634 0.000182 0.001709H2OMultinomialMetrics: deeplearning ** Reported on training data. ** ** Metrics reported on full training frame ** Training Set Metrics: ===================== Extract training frame with `h2o.getFrame("iris")`MSE: (Extract with `h2o.mse`) 0.1183608RMSE: (Extract with `h2o.rmse`) 0.344036Logloss: (Extract with `h2o.logloss`) 0.5279828Mean Per-Class Error: 0.1466667Confusion Matrix: Extract with `h2o.confusionMatrix(<model>,train = TRUE)`) ========================================================================= Confusion Matrix: Row labels: Actual class; Column labels: Predicted class setosa versicolor virginica Error Rate setosa 50 0 0 0.0000 = 0 / 50versicolor 0 50 0 0.0000 = 0 / 50virginica 0 22 28 0.4400 = 22 / 50Totals 50 72 28 0.1467 = 22 / 150Hit Ratio Table: Extract with `h2o.hit_ratio_table(<model>,train = TRUE)`======================================================================= Top-3 Hit Ratios: k hit_ratio1 1 0.8533332 2 1.0000003 3 1.000000> p <- predict(m,test) |========================================================| 100% > p predict setosa versicolor virginica1 setosa 0.9999058 9.417504e-05 6.047099e-232 setosa 0.9996648 3.352197e-04 2.921434e-213 setosa 0.9975189 2.481069e-03 1.479799e-194 setosa 0.9960052 3.994764e-03 2.335468e-205 setosa 0.9978060 2.194044e-03 6.445456e-226 setosa 0.9988394 1.160571e-03 5.431617e-21[20 rows x 4 columns] # 计算混淆矩阵> h2o.confusionMatrix(m) Confusion Matrix: Row labels: Actual class; Column labels: Predicted class setosa versicolor virginica Error Rate setosa 50 0 0 0.0000 = 0 / 50versicolor 0 50 0 0.0000 = 0 / 50virginica 0 22 28 0.4400 = 22 / 50Totals 50 72 28 0.1467 = 22 / 150# 计算均方误差> h2o.mse(m) [1] 0.1183608# 计算其他指标h2o.performance(m,test)
作者:Liam_ml
链接:https://www.jianshu.com/p/5c9a5ff1e0d4