Artificial Neural network Case

2023-02-26

Call Package

lapply(c("h2o","readxl","caret","dplyr","ggplot2","hrbrthemes"),
       library,character.only=T)
## 
## ----------------------------------------------------------------------
## 
## Your next step is to start H2O:
##     > h2o.init()
## 
## For H2O package documentation, ask for help:
##     > ??h2o
## 
## After starting H2O, you can use the Web UI at http://localhost:54321
## For more information visit https://docs.h2o.ai
## 
## ----------------------------------------------------------------------
## 
## Attaching package: 'h2o'
## The following objects are masked from 'package:stats':
## 
##     cor, sd, var
## The following objects are masked from 'package:base':
## 
##     %*%, %in%, &&, ||, apply, as.factor, as.numeric, colnames,
##     colnames<-, ifelse, is.character, is.factor, is.numeric, log,
##     log10, log1p, log2, round, signif, trunc
## Loading required package: ggplot2
## Loading required package: lattice
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.
##       Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and
##       if Arial Narrow is not on your system, please see https://bit.ly/arialnarrow
## [[1]]
## [1] "h2o"       "stats"     "graphics"  "grDevices" "utils"     "datasets" 
## [7] "methods"   "base"     
## 
## [[2]]
## [1] "readxl"    "h2o"       "stats"     "graphics"  "grDevices" "utils"    
## [7] "datasets"  "methods"   "base"     
## 
## [[3]]
##  [1] "caret"     "lattice"   "ggplot2"   "readxl"    "h2o"       "stats"    
##  [7] "graphics"  "grDevices" "utils"     "datasets"  "methods"   "base"     
## 
## [[4]]
##  [1] "dplyr"     "caret"     "lattice"   "ggplot2"   "readxl"    "h2o"      
##  [7] "stats"     "graphics"  "grDevices" "utils"     "datasets"  "methods"  
## [13] "base"     
## 
## [[5]]
##  [1] "dplyr"     "caret"     "lattice"   "ggplot2"   "readxl"    "h2o"      
##  [7] "stats"     "graphics"  "grDevices" "utils"     "datasets"  "methods"  
## [13] "base"     
## 
## [[6]]
##  [1] "hrbrthemes" "dplyr"      "caret"      "lattice"    "ggplot2"   
##  [6] "readxl"     "h2o"        "stats"      "graphics"   "grDevices" 
## [11] "utils"      "datasets"   "methods"    "base"

Input Data

datann <- data.frame(read_excel("D:/Users/Documents/TPM/05. NN Regression - SeoulBikeData.xlsx"))[,-1]

Splitting Data

set.seed(123);i<-createDataPartition(datann$Snowfall..cm.,p=0.8,list=F)
tr<-datann[i,]
ts<-datann[-i,]

Pre-process to H2O Model

h2o.init()
##  Connection successful!
## 
## R is connected to the H2O cluster: 
##     H2O cluster uptime:         2 hours 3 minutes 
##     H2O cluster timezone:       Asia/Bangkok 
##     H2O data parsing timezone:  UTC 
##     H2O cluster version:        3.38.0.1 
##     H2O cluster version age:    5 months and 6 days !!! 
##     H2O cluster name:           H2O_started_from_R_Fitra_eoy050 
##     H2O cluster total nodes:    1 
##     H2O cluster total memory:   0.72 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 
##     R Version:                  R version 4.2.2 (2022-10-31 ucrt)
## Warning in h2o.clusterInfo(): 
## Your H2O cluster version is too old (5 months and 6 days)!
## Please download and install the latest version from http://h2o.ai/download/
trh<-as.h2o(tr)
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |======================================================================| 100%
tsh<-as.h2o(ts)
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |======================================================================| 100%

Model 1

dl<-h2o.deeplearning(x=names(trh)[-1],y=names(trh)[1],trh,
                      nfolds=12,epochs=115,seed=25,
                      keep_cross_validation_predictions=T,
                      activation="Rectifier");dl #hidden default (200,200)
## Warning in .h2o.processResponseWarnings(res): Dropping bad and constant columns: [Holiday, Functioning.Day, Seasons].
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |=                                                                     |   1%
  |                                                                            
  |=                                                                     |   2%
  |                                                                            
  |==                                                                    |   2%
  |                                                                            
  |===                                                                   |   4%
  |                                                                            
  |====                                                                  |   6%
  |                                                                            
  |=====                                                                 |   7%
  |                                                                            
  |=====                                                                 |   8%
  |                                                                            
  |======                                                                |   9%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |========                                                              |  11%
  |                                                                            
  |========                                                              |  12%
  |                                                                            
  |=========                                                             |  13%
  |                                                                            
  |==========                                                            |  14%
  |                                                                            
  |==========                                                            |  15%
  |                                                                            
  |===========                                                           |  16%
  |                                                                            
  |============                                                          |  17%
  |                                                                            
  |============                                                          |  18%
  |                                                                            
  |=============                                                         |  18%
  |                                                                            
  |=============                                                         |  19%
  |                                                                            
  |==============                                                        |  20%
  |                                                                            
  |===============                                                       |  21%
  |                                                                            
  |===============                                                       |  22%
  |                                                                            
  |================                                                      |  23%
  |                                                                            
  |=================                                                     |  24%
  |                                                                            
  |==================                                                    |  25%
  |                                                                            
  |==================                                                    |  26%
  |                                                                            
  |===================                                                   |  27%
  |                                                                            
  |===================                                                   |  28%
  |                                                                            
  |====================                                                  |  28%
  |                                                                            
  |====================                                                  |  29%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |======================                                                |  31%
  |                                                                            
  |=======================                                               |  33%
  |                                                                            
  |========================                                              |  34%
  |                                                                            
  |========================                                              |  35%
  |                                                                            
  |=========================                                             |  35%
  |                                                                            
  |=========================                                             |  36%
  |                                                                            
  |==========================                                            |  37%
  |                                                                            
  |===========================                                           |  38%
  |                                                                            
  |===========================                                           |  39%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |============================                                          |  41%
  |                                                                            
  |=============================                                         |  41%
  |                                                                            
  |=============================                                         |  42%
  |                                                                            
  |==============================                                        |  42%
  |                                                                            
  |==============================                                        |  43%
  |                                                                            
  |==============================                                        |  44%
  |                                                                            
  |===============================                                       |  44%
  |                                                                            
  |===============================                                       |  45%
  |                                                                            
  |================================                                      |  45%
  |                                                                            
  |================================                                      |  46%
  |                                                                            
  |=================================                                     |  47%
  |                                                                            
  |=================================                                     |  48%
  |                                                                            
  |==================================                                    |  48%
  |                                                                            
  |==================================                                    |  49%
  |                                                                            
  |===================================                                   |  49%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |===================================                                   |  51%
  |                                                                            
  |====================================                                  |  51%
  |                                                                            
  |====================================                                  |  52%
  |                                                                            
  |=====================================                                 |  52%
  |                                                                            
  |=====================================                                 |  53%
  |                                                                            
  |======================================                                |  54%
  |                                                                            
  |======================================                                |  55%
  |                                                                            
  |=======================================                               |  55%
  |                                                                            
  |=======================================                               |  56%
  |                                                                            
  |========================================                              |  57%
  |                                                                            
  |=========================================                             |  58%
  |                                                                            
  |=========================================                             |  59%
  |                                                                            
  |==========================================                            |  59%
  |                                                                            
  |===========================================                           |  61%
  |                                                                            
  |============================================                          |  62%
  |                                                                            
  |=============================================                         |  64%
  |                                                                            
  |=============================================                         |  65%
  |                                                                            
  |==============================================                        |  65%
  |                                                                            
  |==============================================                        |  66%
  |                                                                            
  |===============================================                       |  67%
  |                                                                            
  |===============================================                       |  68%
  |                                                                            
  |================================================                      |  68%
  |                                                                            
  |================================================                      |  69%
  |                                                                            
  |=================================================                     |  69%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |==================================================                    |  71%
  |                                                                            
  |==================================================                    |  72%
  |                                                                            
  |===================================================                   |  72%
  |                                                                            
  |===================================================                   |  73%
  |                                                                            
  |====================================================                  |  74%
  |                                                                            
  |====================================================                  |  75%
  |                                                                            
  |=====================================================                 |  75%
  |                                                                            
  |=====================================================                 |  76%
  |                                                                            
  |======================================================                |  77%
  |                                                                            
  |==========================================================            |  83%
  |                                                                            
  |===========================================================           |  84%
  |                                                                            
  |============================================================          |  85%
  |                                                                            
  |============================================================          |  86%
  |                                                                            
  |=============================================================         |  86%
  |                                                                            
  |=============================================================         |  87%
  |                                                                            
  |=============================================================         |  88%
  |                                                                            
  |==============================================================        |  88%
  |                                                                            
  |==============================================================        |  89%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |===============================================================       |  91%
  |                                                                            
  |================================================================      |  91%
  |                                                                            
  |================================================================      |  92%
  |                                                                            
  |=================================================================     |  92%
  |                                                                            
  |=================================================================     |  93%
  |                                                                            
  |==================================================================    |  94%
  |                                                                            
  |==================================================================    |  95%
  |                                                                            
  |===================================================================   |  95%
  |                                                                            
  |===================================================================   |  96%
  |                                                                            
  |====================================================================  |  97%
  |                                                                            
  |====================================================================  |  98%
  |                                                                            
  |===================================================================== |  98%
  |                                                                            
  |===================================================================== |  99%
  |                                                                            
  |======================================================================|  99%
  |                                                                            
  |======================================================================| 100%
## Model Details:
## ==============
## 
## H2ORegressionModel: deeplearning
## Model ID:  DeepLearning_model_R_1677385886459_4 
## Status of Neuron Layers: predicting Rented.Bike.Count, regression, gaussian distribution, Quadratic loss, 42.401 weights/biases, 506,0 KB, 840.960 training samples, mini-batch size 1
##   layer units      type dropout       l1       l2 mean_rate rate_rms momentum
## 1     1     9     Input  0.00 %       NA       NA        NA       NA       NA
## 2     2   200 Rectifier  0.00 % 0.000000 0.000000  0.005278 0.007651 0.000000
## 3     3   200 Rectifier  0.00 % 0.000000 0.000000  0.112685 0.141129 0.000000
## 4     4     1    Linear      NA 0.000000 0.000000  0.002310 0.001660 0.000000
##   mean_weight weight_rms mean_bias bias_rms
## 1          NA         NA        NA       NA
## 2   -0.041115   0.254775  0.152359 0.234858
## 3   -0.055206   0.129769  0.776165 0.227415
## 4   -0.035732   0.159716  1.064322 0.000000
## 
## 
## H2ORegressionMetrics: deeplearning
## ** Reported on training data. **
## ** Metrics reported on full training frame **
## 
## MSE:  97280.29
## RMSE:  311.8979
## MAE:  217.0225
## RMSLE:  NaN
## Mean Residual Deviance :  97280.29
## 
## 
## 
## H2ORegressionMetrics: deeplearning
## ** Reported on cross-validation data. **
## ** 12-fold cross-validation on training data (Metrics computed for combined holdout predictions) **
## 
## MSE:  130254.2
## RMSE:  360.9074
## MAE:  239.3832
## RMSLE:  NaN
## Mean Residual Deviance :  130254.2
## 
## 
## Cross-Validation Metrics Summary: 
##                                 mean           sd    cv_1_valid    cv_2_valid
## mae                       239.416500    17.039099    253.506180    224.759080
## mean_residual_deviance 130257.440000 14178.136000 146392.100000 125653.690000
## mse                    130257.440000 14178.136000 146392.100000 125653.690000
## r2                          0.686359     0.038817      0.641775      0.721182
## residual_deviance      130257.440000 14178.136000 146392.100000 125653.690000
## rmse                      360.399840    20.073936    382.612180    354.476620
## rmsle                             NA     0.000000            NA            NA
##                           cv_3_valid    cv_4_valid    cv_5_valid    cv_6_valid
## mae                       248.222530    236.064360    242.256730    210.644030
## mean_residual_deviance 141776.660000 133401.000000 138339.950000 107786.160000
## mse                    141776.660000 133401.000000 138339.950000 107786.160000
## r2                          0.646831      0.650237      0.697647      0.751430
## residual_deviance      141776.660000 133401.000000 138339.950000 107786.160000
## rmse                      376.532400    365.241030    371.940800    328.308000
## rmsle                             NA            NA            NA            NA
##                           cv_7_valid    cv_8_valid    cv_9_valid   cv_10_valid
## mae                       266.882800    249.794900    236.106800    239.309160
## mean_residual_deviance 149329.690000 130268.875000 129489.305000 123209.570000
## mse                    149329.690000 130268.875000 129489.305000 123209.570000
## r2                          0.643817      0.668878      0.719508      0.701442
## residual_deviance      149329.690000 130268.875000 129489.305000 123209.570000
## rmse                      386.432000    360.927800    359.846220    351.012200
## rmsle                             NA            NA            NA            NA
##                          cv_11_valid   cv_12_valid
## mae                       253.855870    211.595540
## mean_residual_deviance 135101.690000 102340.540000
## mse                    135101.690000 102340.540000
## r2                          0.661522      0.732035
## residual_deviance      135101.690000 102340.540000
## rmse                      367.561800    319.907070
## rmsle                             NA            NA
h<-h2o.performance(dl);r<-h@metrics$r2;r
## [1] 0.766766

Model 2

dl1<-h2o.deeplearning(x=names(trh)[-1],y=names(trh)[1],trh,
                     nfolds=12,epochs=115,seed=25,
                     keep_cross_validation_predictions=T,
                     hidden = c(300,200,100),activation="Rectifier");dl1
## Warning in .h2o.processResponseWarnings(res): Dropping bad and constant columns: [Holiday, Functioning.Day, Seasons].
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |                                                                      |   1%
  |                                                                            
  |=                                                                     |   1%
  |                                                                            
  |=                                                                     |   2%
  |                                                                            
  |==                                                                    |   2%
  |                                                                            
  |==                                                                    |   3%
  |                                                                            
  |===                                                                   |   4%
  |                                                                            
  |===                                                                   |   5%
  |                                                                            
  |====                                                                  |   5%
  |                                                                            
  |====                                                                  |   6%
  |                                                                            
  |=====                                                                 |   7%
  |                                                                            
  |=====                                                                 |   8%
  |                                                                            
  |======                                                                |   8%
  |                                                                            
  |======                                                                |   9%
  |                                                                            
  |=======                                                               |   9%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |=======                                                               |  11%
  |                                                                            
  |========                                                              |  11%
  |                                                                            
  |========                                                              |  12%
  |                                                                            
  |=========                                                             |  12%
  |                                                                            
  |=========                                                             |  13%
  |                                                                            
  |==========                                                            |  14%
  |                                                                            
  |==========                                                            |  15%
  |                                                                            
  |===========                                                           |  15%
  |                                                                            
  |===========                                                           |  16%
  |                                                                            
  |============                                                          |  17%
  |                                                                            
  |============                                                          |  18%
  |                                                                            
  |=============                                                         |  18%
  |                                                                            
  |=============                                                         |  19%
  |                                                                            
  |==============                                                        |  19%
  |                                                                            
  |==============                                                        |  20%
  |                                                                            
  |==============                                                        |  21%
  |                                                                            
  |===============                                                       |  21%
  |                                                                            
  |===============                                                       |  22%
  |                                                                            
  |================                                                      |  22%
  |                                                                            
  |================                                                      |  23%
  |                                                                            
  |================                                                      |  24%
  |                                                                            
  |=================                                                     |  24%
  |                                                                            
  |=================                                                     |  25%
  |                                                                            
  |==================                                                    |  25%
  |                                                                            
  |==================                                                    |  26%
  |                                                                            
  |===================                                                   |  27%
  |                                                                            
  |===================                                                   |  28%
  |                                                                            
  |====================                                                  |  28%
  |                                                                            
  |====================                                                  |  29%
  |                                                                            
  |=====================                                                 |  29%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |==========================                                            |  38%
  |                                                                            
  |===========================                                           |  38%
  |                                                                            
  |===========================                                           |  39%
  |                                                                            
  |============================                                          |  39%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |============================                                          |  41%
  |                                                                            
  |=============================                                         |  41%
  |                                                                            
  |=============================                                         |  42%
  |                                                                            
  |==============================                                        |  42%
  |                                                                            
  |==============================                                        |  43%
  |                                                                            
  |==============================                                        |  44%
  |                                                                            
  |===============================                                       |  44%
  |                                                                            
  |===============================                                       |  45%
  |                                                                            
  |================================                                      |  45%
  |                                                                            
  |================================                                      |  46%
  |                                                                            
  |=================================                                     |  47%
  |                                                                            
  |=================================                                     |  48%
  |                                                                            
  |==================================                                    |  48%
  |                                                                            
  |==================================                                    |  49%
  |                                                                            
  |===================================                                   |  49%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |===================================                                   |  51%
  |                                                                            
  |====================================                                  |  51%
  |                                                                            
  |====================================                                  |  52%
  |                                                                            
  |=====================================                                 |  52%
  |                                                                            
  |=====================================                                 |  53%
  |                                                                            
  |======================================                                |  54%
  |                                                                            
  |======================================                                |  55%
  |                                                                            
  |=======================================                               |  55%
  |                                                                            
  |=======================================                               |  56%
  |                                                                            
  |========================================                              |  57%
  |                                                                            
  |========================================                              |  58%
  |                                                                            
  |=========================================                             |  58%
  |                                                                            
  |=========================================                             |  59%
  |                                                                            
  |==========================================                            |  60%
  |                                                                            
  |===========================================                           |  61%
  |                                                                            
  |===========================================                           |  62%
  |                                                                            
  |============================================                          |  62%
  |                                                                            
  |============================================                          |  63%
  |                                                                            
  |=============================================                         |  64%
  |                                                                            
  |=============================================                         |  65%
  |                                                                            
  |==============================================                        |  65%
  |                                                                            
  |==============================================                        |  66%
  |                                                                            
  |===============================================                       |  67%
  |                                                                            
  |================================================                      |  68%
  |                                                                            
  |================================================                      |  69%
  |                                                                            
  |=================================================                     |  69%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |=================================================                     |  71%
  |                                                                            
  |==================================================                    |  71%
  |                                                                            
  |==================================================                    |  72%
  |                                                                            
  |===================================================                   |  72%
  |                                                                            
  |===================================================                   |  73%
  |                                                                            
  |===================================================                   |  74%
  |                                                                            
  |====================================================                  |  74%
  |                                                                            
  |====================================================                  |  75%Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, urlSuffix = urlSuffix,  : 
##   Unexpected CURL error: Timeout was reached: [localhost:54321] Resolving timed out after 11929 milliseconds
## [1] "Job request failed Unexpected CURL error: Timeout was reached: [localhost:54321] Resolving timed out after 11929 milliseconds, will retry after 3s."
## 
  |                                                                            
  |=========================================================             |  81%
  |                                                                            
  |=========================================================             |  82%
  |                                                                            
  |==========================================================            |  82%
  |                                                                            
  |==========================================================            |  83%Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, urlSuffix = urlSuffix,  : 
##   Unexpected CURL error: Timeout was reached: [localhost:54321] Connection time-out
## [1] "Job request failed Unexpected CURL error: Timeout was reached: [localhost:54321] Connection time-out, will retry after 3s."
## 
  |                                                                            
  |===========================================================           |  84%
  |                                                                            
  |===========================================================           |  85%
  |                                                                            
  |============================================================          |  85%
  |                                                                            
  |============================================================          |  86%
  |                                                                            
  |=============================================================         |  86%
  |                                                                            
  |=============================================================         |  87%
  |                                                                            
  |=============================================================         |  88%
  |                                                                            
  |==============================================================        |  88%
  |                                                                            
  |==============================================================        |  89%
  |                                                                            
  |===============================================================       |  89%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |===============================================================       |  91%
  |                                                                            
  |================================================================      |  91%
  |                                                                            
  |================================================================      |  92%
  |                                                                            
  |=================================================================     |  92%
  |                                                                            
  |=================================================================     |  93%
  |                                                                            
  |=================================================================     |  94%
  |                                                                            
  |==================================================================    |  94%
  |                                                                            
  |==================================================================    |  95%
  |                                                                            
  |===================================================================   |  95%
  |                                                                            
  |===================================================================   |  96%
  |                                                                            
  |====================================================================  |  97%
  |                                                                            
  |====================================================================  |  98%
  |                                                                            
  |===================================================================== |  98%
  |                                                                            
  |===================================================================== |  99%
  |                                                                            
  |======================================================================|  99%
  |                                                                            
  |======================================================================| 100%
## Model Details:
## ==============
## 
## H2ORegressionModel: deeplearning
## Model ID:  DeepLearning_model_R_1677385886459_5 
## Status of Neuron Layers: predicting Rented.Bike.Count, regression, gaussian distribution, Quadratic loss, 83.401 weights/biases, 989,5 KB, 813.601 training samples, mini-batch size 1
##   layer units      type dropout       l1       l2 mean_rate rate_rms momentum
## 1     1     9     Input  0.00 %       NA       NA        NA       NA       NA
## 2     2   300 Rectifier  0.00 % 0.000000 0.000000  0.028458 0.030978 0.000000
## 3     3   200 Rectifier  0.00 % 0.000000 0.000000  0.021209 0.027022 0.000000
## 4     4   100 Rectifier  0.00 % 0.000000 0.000000  0.026573 0.047228 0.000000
## 5     5     1    Linear      NA 0.000000 0.000000  0.000689 0.000326 0.000000
##   mean_weight weight_rms mean_bias bias_rms
## 1          NA         NA        NA       NA
## 2   -0.029176   0.247557  0.361664 0.189008
## 3   -0.033128   0.104047  0.929238 0.061913
## 4   -0.041477   0.145876  0.783925 0.462913
## 5   -0.020998   0.177461  0.066837 0.000000
## 
## 
## H2ORegressionMetrics: deeplearning
## ** Reported on training data. **
## ** Metrics reported on full training frame **
## 
## MSE:  67553.27
## RMSE:  259.9101
## MAE:  169.7145
## RMSLE:  NaN
## Mean Residual Deviance :  67553.27
## 
## 
## 
## H2ORegressionMetrics: deeplearning
## ** Reported on cross-validation data. **
## ** 12-fold cross-validation on training data (Metrics computed for combined holdout predictions) **
## 
## MSE:  115450.5
## RMSE:  339.7801
## MAE:  217.0844
## RMSLE:  NaN
## Mean Residual Deviance :  115450.5
## 
## 
## Cross-Validation Metrics Summary: 
##                                 mean           sd    cv_1_valid    cv_2_valid
## mae                       217.286240    12.821776    222.566120    223.050690
## mean_residual_deviance 115458.150000 11996.120000 115033.590000 128246.540000
## mse                    115458.150000 11996.120000 115033.590000 128246.540000
## r2                          0.722425     0.028207      0.718510      0.715428
## residual_deviance      115458.150000 11996.120000 115033.590000 128246.540000
## rmse                      339.364000    17.793196    339.166020    358.115260
## rmsle                             NA     0.000000            NA            NA
##                           cv_3_valid    cv_4_valid    cv_5_valid   cv_6_valid
## mae                       238.294390    214.660680    234.075600   195.019360
## mean_residual_deviance 126683.810000 119690.010000 134555.390000 95446.875000
## mse                    126683.810000 119690.010000 134555.390000 95446.875000
## r2                          0.684427      0.686186      0.705918     0.779886
## residual_deviance      126683.810000 119690.010000 134555.390000 95446.875000
## rmse                      355.926700    345.962430    366.817900   308.944800
## rmsle                             NA            NA            NA           NA
##                           cv_7_valid    cv_8_valid    cv_9_valid  cv_10_valid
## mae                       222.292560    220.790070    208.514070   198.378080
## mean_residual_deviance 121915.305000 103861.770000 118993.090000 98665.350000
## mse                    121915.305000 103861.770000 118993.090000 98665.350000
## r2                          0.709206      0.736000      0.742244     0.760917
## residual_deviance      121915.305000 103861.770000 118993.090000 98665.350000
## rmse                      349.163730    322.275900    344.953770   314.110400
## rmsle                             NA            NA            NA           NA
##                          cv_11_valid   cv_12_valid
## mae                       210.531510    219.261800
## mean_residual_deviance 112486.940000 109919.164000
## mse                    112486.940000 109919.164000
## r2                          0.718180      0.712192
## residual_deviance      112486.940000 109919.164000
## rmse                      335.390720    331.540600
## rmsle                             NA            NA
h1<-h2o.performance(dl1);r1<-h1@metrics$r2;r1
## [1] 0.8380379

Model 3

dl2<-h2o.deeplearning(x=names(trh)[-1],y=names(trh)[1],trh,
                     nfolds=12,epochs=115,seed=25,
                     keep_cross_validation_predictions=T,
                     hidden = c(200,200,200),activation="Rectifier");dl2
## Warning in .h2o.processResponseWarnings(res): Dropping bad and constant columns: [Holiday, Functioning.Day, Seasons].
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |                                                                      |   1%
  |                                                                            
  |=                                                                     |   1%
  |                                                                            
  |=                                                                     |   2%
  |                                                                            
  |==                                                                    |   2%
  |                                                                            
  |==                                                                    |   3%
  |                                                                            
  |===                                                                   |   4%
  |                                                                            
  |===                                                                   |   5%
  |                                                                            
  |====                                                                  |   5%
  |                                                                            
  |====                                                                  |   6%
  |                                                                            
  |=====                                                                 |   6%
  |                                                                            
  |=====                                                                 |   7%
  |                                                                            
  |=====                                                                 |   8%
  |                                                                            
  |======                                                                |   8%
  |                                                                            
  |======                                                                |   9%
  |                                                                            
  |=======                                                               |   9%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |========                                                              |  11%
  |                                                                            
  |========                                                              |  12%
  |                                                                            
  |=========                                                             |  13%
  |                                                                            
  |==========                                                            |  14%
  |                                                                            
  |==========                                                            |  15%
  |                                                                            
  |===========                                                           |  16%
  |                                                                            
  |============                                                          |  17%
  |                                                                            
  |============                                                          |  18%
  |                                                                            
  |=============                                                         |  18%
  |                                                                            
  |=============                                                         |  19%
  |                                                                            
  |==============                                                        |  20%
  |                                                                            
  |==============                                                        |  21%
  |                                                                            
  |===============                                                       |  21%
  |                                                                            
  |===============                                                       |  22%
  |                                                                            
  |================                                                      |  23%
  |                                                                            
  |=================                                                     |  24%
  |                                                                            
  |==========================                                            |  37%
  |                                                                            
  |===============================                                       |  44%
  |                                                                            
  |===============================                                       |  45%
  |                                                                            
  |================================                                      |  45%
  |                                                                            
  |================================                                      |  46%
  |                                                                            
  |=================================                                     |  47%
  |                                                                            
  |=================================                                     |  48%
  |                                                                            
  |==================================                                    |  48%
  |                                                                            
  |==================================                                    |  49%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |====================================                                  |  51%
  |                                                                            
  |====================================                                  |  52%
  |                                                                            
  |=====================================                                 |  52%
  |                                                                            
  |=====================================                                 |  53%Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, urlSuffix = urlSuffix,  : 
##   Unexpected CURL error: Timeout was reached: [localhost:54321] Connection timed out after 14546 milliseconds
## [1] "Job request failed Unexpected CURL error: Timeout was reached: [localhost:54321] Connection timed out after 14546 milliseconds, will retry after 3s."
## 
  |                                                                            
  |======================================                                |  54%
  |                                                                            
  |======================================                                |  55%
  |                                                                            
  |=======================================                               |  55%
  |                                                                            
  |=======================================                               |  56%
  |                                                                            
  |========================================                              |  57%
  |                                                                            
  |========================================                              |  58%
  |                                                                            
  |=========================================                             |  58%
  |                                                                            
  |=========================================                             |  59%
  |                                                                            
  |==========================================                            |  59%
  |                                                                            
  |==========================================                            |  60%
  |                                                                            
  |===========================================                           |  61%
  |                                                                            
  |===========================================                           |  62%
  |                                                                            
  |============================================                          |  62%
  |                                                                            
  |============================================                          |  63%
  |                                                                            
  |=============================================                         |  64%
  |                                                                            
  |=============================================                         |  65%
  |                                                                            
  |==============================================                        |  65%
  |                                                                            
  |==============================================                        |  66%
  |                                                                            
  |===============================================                       |  66%
  |                                                                            
  |===============================================                       |  67%
  |                                                                            
  |===============================================                       |  68%
  |                                                                            
  |================================================                      |  68%
  |                                                                            
  |================================================                      |  69%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |=================================================                     |  71%
  |                                                                            
  |==================================================                    |  71%
  |                                                                            
  |==================================================                    |  72%
  |                                                                            
  |====================================================                  |  75%
  |                                                                            
  |=====================================================                 |  75%
  |                                                                            
  |=====================================================                 |  76%
  |                                                                            
  |======================================================                |  77%Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, urlSuffix = urlSuffix,  : 
##   Unexpected CURL error: Timeout was reached: [localhost:54321] Connection timed out after 10108 milliseconds
## [1] "Job request failed Unexpected CURL error: Timeout was reached: [localhost:54321] Connection timed out after 10108 milliseconds, will retry after 3s."
## 
  |                                                                            
  |======================================================                |  78%
  |                                                                            
  |=======================================================               |  78%
  |                                                                            
  |=======================================================               |  79%
  |                                                                            
  |========================================================              |  79%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |========================================================              |  81%
  |                                                                            
  |=========================================================             |  81%
  |                                                                            
  |=========================================================             |  82%
  |                                                                            
  |==========================================================            |  82%
  |                                                                            
  |==========================================================            |  83%
  |                                                                            
  |===========================================================           |  84%
  |                                                                            
  |===========================================================           |  85%
  |                                                                            
  |============================================================          |  85%
  |                                                                            
  |============================================================          |  86%
  |                                                                            
  |=============================================================         |  86%
  |                                                                            
  |=============================================================         |  87%
  |                                                                            
  |=============================================================         |  88%
  |                                                                            
  |==============================================================        |  88%
  |                                                                            
  |==============================================================        |  89%
  |                                                                            
  |===============================================================       |  89%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |===============================================================       |  91%
  |                                                                            
  |================================================================      |  91%
  |                                                                            
  |================================================================      |  92%
  |                                                                            
  |=================================================================     |  92%
  |                                                                            
  |=================================================================     |  93%
  |                                                                            
  |==================================================================    |  94%
  |                                                                            
  |==================================================================    |  95%
  |                                                                            
  |===================================================================   |  95%
  |                                                                            
  |===================================================================   |  96%
  |                                                                            
  |====================================================================  |  96%
  |                                                                            
  |====================================================================  |  97%
  |                                                                            
  |====================================================================  |  98%
  |                                                                            
  |===================================================================== |  98%
  |                                                                            
  |===================================================================== |  99%
  |                                                                            
  |======================================================================|  99%
  |                                                                            
  |======================================================================| 100%Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, urlSuffix = urlSuffix,  : 
##   Unexpected CURL error: Timeout was reached: [localhost:54321] Connection time-out
## [1] "Job request failed Unexpected CURL error: Timeout was reached: [localhost:54321] Connection time-out, will retry after 3s."
## Model Details:
## ==============
## 
## H2ORegressionModel: deeplearning
## Model ID:  DeepLearning_model_R_1677385886459_6 
## Status of Neuron Layers: predicting Rented.Bike.Count, regression, gaussian distribution, Quadratic loss, 82.601 weights/biases, 980,1 KB, 812.928 training samples, mini-batch size 1
##   layer units      type dropout       l1       l2 mean_rate rate_rms momentum
## 1     1     9     Input  0.00 %       NA       NA        NA       NA       NA
## 2     2   200 Rectifier  0.00 % 0.000000 0.000000  0.004968 0.005339 0.000000
## 3     3   200 Rectifier  0.00 % 0.000000 0.000000  0.018597 0.019647 0.000000
## 4     4   200 Rectifier  0.00 % 0.000000 0.000000  0.050648 0.076482 0.000000
## 5     5     1    Linear      NA 0.000000 0.000000  0.001098 0.000517 0.000000
##   mean_weight weight_rms mean_bias bias_rms
## 1          NA         NA        NA       NA
## 2   -0.026467   0.270889  0.368908 0.233145
## 3   -0.036813   0.106407  0.949768 0.084539
## 4   -0.032635   0.106966  0.571763 0.420903
## 5    0.004344   0.155217  0.991146 0.000000
## 
## 
## H2ORegressionMetrics: deeplearning
## ** Reported on training data. **
## ** Metrics reported on full training frame **
## 
## MSE:  99088.71
## RMSE:  314.7836
## MAE:  228.2953
## RMSLE:  NaN
## Mean Residual Deviance :  99088.71
## 
## 
## 
## H2ORegressionMetrics: deeplearning
## ** Reported on cross-validation data. **
## ** 12-fold cross-validation on training data (Metrics computed for combined holdout predictions) **
## 
## MSE:  118717.8
## RMSE:  344.5545
## MAE:  224.4222
## RMSLE:  NaN
## Mean Residual Deviance :  118717.8
## 
## 
## Cross-Validation Metrics Summary: 
##                                 mean           sd    cv_1_valid    cv_2_valid
## mae                       224.538210    12.931416    229.943740    227.762940
## mean_residual_deviance 118745.140000 12390.155000 118970.470000 127198.870000
## mse                    118745.140000 12390.155000 118970.470000 127198.870000
## r2                          0.714554     0.028988      0.708876      0.717753
## residual_deviance      118745.140000 12390.155000 118970.470000 127198.870000
## rmse                      344.159180    18.078484    344.920960    356.649500
## rmsle                       1.262317     0.000000            NA            NA
##                           cv_3_valid    cv_4_valid    cv_5_valid    cv_6_valid
## mae                       240.753400    221.731830    241.072950    205.896090
## mean_residual_deviance 131161.280000 119731.270000 138527.360000 100553.220000
## mse                    131161.280000 119731.270000 138527.360000 100553.220000
## r2                          0.673274      0.686078      0.697237      0.768110
## residual_deviance      131161.280000 119731.270000 138527.360000 100553.220000
## rmse                      362.161960    346.022060    372.192630    317.101260
## rmsle                       1.262317            NA            NA            NA
##                           cv_7_valid    cv_8_valid    cv_9_valid   cv_10_valid
## mae                       241.040420    233.207140    218.719680    211.715530
## mean_residual_deviance 132417.160000 117900.625000 118666.990000 103972.950000
## mse                    132417.160000 117900.625000 118666.990000 103972.950000
## r2                          0.684157      0.700316      0.742950      0.748056
## residual_deviance      132417.160000 117900.625000 118666.990000 103972.950000
## rmse                      363.891700    343.366600    344.480770    322.448360
## rmsle                             NA            NA            NA            NA
##                          cv_11_valid   cv_12_valid
## mae                       213.779880    208.834950
## mean_residual_deviance 114975.770000 100865.695000
## mse                    114975.770000 100865.695000
## r2                          0.711945      0.735897
## residual_deviance      114975.770000 100865.695000
## rmse                      339.080780    317.593600
## rmsle                             NA            NA
h2<-h2o.performance(dl2);r2<-h2@metrics$r2;r2
## [1] 0.7624303
d<-data.frame(hidden=c("Default","{300,200,100}","{200,200,200}"),
           r2=round(c(r,r1,r2),2))

Plot comparation of R2 for each layer

ggplot(d,aes(x=hidden,y=r2,fill=hidden))+geom_bar(stat="identity")+
  theme_ipsum_rc(axis_title_just = "center",axis_text_size = 12)+
  labs(fill="Hidden layer",y="")+scale_fill_brewer(palette="Blues")+
  coord_polar("y")+theme(axis.text.y.left = element_blank(),
                         axis.title.y.left = element_blank())+coord_polar("y")
## Coordinate system already present. Adding new coordinate system, which will
## replace the existing one.
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database

## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database

## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database

## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

#best model: Model 2 (3 hidden layer, 300 neuron layer 1, 200 neuron di layer 2, dan 100 neuron di layer 1)

Learning Curve Plot

lc1<-h2o.learning_curve_plot(dl1,"rmse",cv_lines = F,cv_ribbon = F)
ggplot(lc1$data,aes(x=x,y=metric))+geom_point(col="coral",size=4)+
  geom_line(col="steelblue",lwd=1.6)+
  theme_ipsum_rc(axis_title_just = "center",axis_title_size = 12)+
  labs(x="\nEpochs",y="RMSE\n")+geom_vline(xintercept = 116.034709514103,
                                           col="darkgreen",lwd=1.4,lty=5)+
  geom_text(aes(x=116.04,y=250,label="Selected epochs: 115.53"),
            hjust=1.05,col="darkgreen",size=4.5,vjust=-16.8)
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

Variable Importance Plot

hpi<-h2o.permutation_importance_plot(dl1,tsh,metric="RMSE",seed=123);hpi

##                     Variable Relative Importance Scaled Importance Percentage
## 1                       Hour           286.70008        1.00000000 0.26325138
## 2            Temperature..C.           228.83708        0.79817584 0.21012090
## 3    Solar.Radiation..MJ.m2.           214.40920        0.74785189 0.19687305
## 4  Dew.point.temperature..C.           147.85937        0.51572837 0.13576621
## 5                Humidity...           121.82426        0.42491882 0.11186047
## 6               Rainfall.mm.            32.02179        0.11169091 0.02940279
## 7           Wind.speed..m.s.            22.33465        0.07790250 0.02050794
## 8              Snowfall..cm.            20.29776        0.07079789 0.01863764
## 9           Visibility..10m.            14.78921        0.05158427 0.01357963
## 10                   Holiday             0.00000        0.00000000 0.00000000
## 11           Functioning.Day             0.00000        0.00000000 0.00000000
## 12                   Seasons             0.00000        0.00000000 0.00000000

Prediction

h2o.predict(dl1,tsh)
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |======================================================================| 100%
##     predict
## 1 273.35520
## 2 563.26095
## 3 259.65934
## 4  93.31756
## 5  88.21706
## 6 365.32417
## 
## [1752 rows x 1 column]

Prediction Performance

hv<-h2o.performance(dl1,tsh);hv;hv@metrics$r2
## H2ORegressionMetrics: deeplearning
## 
## MSE:  108592.1
## RMSE:  329.5332
## MAE:  208.7487
## RMSLE:  NaN
## Mean Residual Deviance :  108592.1
## [1] 0.7360788
#sedikit lebih kecil dibandingkan r2 training

Difference of R2 (training vs testing)

h1@metrics$r2-hv@metrics$r2 #Kecil perbedaannya sehingga tidak terdapat overfitting
## [1] 0.1019592