library(h2o)
## 
## ----------------------------------------------------------------------
## 
## 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 http://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
h2o.init()
## 
## H2O is not running yet, starting it now...
## 
## Note:  In case of errors look at the following log files:
##     C:\Users\somy\AppData\Local\Temp\RtmpiAVn1B/h2o_somy_started_from_r.out
##     C:\Users\somy\AppData\Local\Temp\RtmpiAVn1B/h2o_somy_started_from_r.err
## 
## 
## Starting H2O JVM and connecting: .. Connection successful!
## 
## R is connected to the H2O cluster: 
##     H2O cluster uptime:         21 seconds 483 milliseconds 
##     H2O cluster timezone:       Asia/Kolkata 
##     H2O data parsing timezone:  UTC 
##     H2O cluster version:        3.26.0.4804 
##     H2O cluster version age:    11 days  
##     H2O cluster name:           H2O_started_from_R_somy_kxv057 
##     H2O cluster total nodes:    1 
##     H2O cluster total memory:   1.75 GB 
##     H2O cluster total cores:    8 
##     H2O cluster allowed cores:  8 
##     H2O cluster healthy:        TRUE 
##     H2O Connection ip:          localhost 
##     H2O Connection port:        54321 
##     H2O Connection proxy:       NA 
##     H2O Internal Security:      FALSE 
##     H2O API Extensions:         Amazon S3, Algos, AutoML, Core V3, TargetEncoder, Core V4 
##     R Version:                  R version 3.6.1 (2019-07-05)
#to see the h2o flow in your localhost type : http://127.0.0.1:54321
library(MASS)

Datafram<-Boston

scale.dat<-scale(Datafram)

colMeans(scale.dat)
##          crim            zn         indus          chas           nox 
## -6.899468e-18  2.298337e-17  1.516683e-17 -3.510587e-18 -2.149412e-16 
##            rm           age           dis           rad           tax 
## -1.058524e-16 -1.645039e-16  1.144506e-16  4.651527e-17  1.906139e-17 
##       ptratio         black         lstat          medv 
## -3.931034e-16 -1.155991e-16 -7.012260e-17 -1.379311e-16
apply(scale.dat,2,sd)
##    crim      zn   indus    chas     nox      rm     age     dis     rad 
##       1       1       1       1       1       1       1       1       1 
##     tax ptratio   black   lstat    medv 
##       1       1       1       1       1
scale.dat<-as.data.frame(scale.dat)

y<-"medv"

x<-setdiff(colnames(scale.dat),y)

ind<-sample(1:nrow(Datafram),400)

trainDF<-Datafram[ind,]
testDF<-Datafram[-ind,]


?h2o.deeplearning
## starting httpd help server ...
##  done
model<-h2o.deeplearning(x=x,y=y,seed = 1234,training_frame = as.h2o(trainDF),nfolds = 3,stopping_rounds = 7,epochs = 500,overwrite_with_best_model = T
                        ,activation = 'Tanh',input_dropout_ratio = 0.1,hidden = c(10,10,10),l1 = 6e-4,loss = 'Automatic',distribution = "AUTO",
                        stopping_metric = 'MSE')
## 
  |                                                                       
  |                                                                 |   0%
  |                                                                       
  |=================================================================| 100%
## 
  |                                                                       
  |                                                                 |   0%
  |                                                                       
  |=================================================                |  76%
  |                                                                       
  |=======================================================          |  84%
  |                                                                       
  |================================================================ |  98%
  |                                                                       
  |=================================================================| 100%
plot(model)

pred<-as.data.frame(predict(model,as.h2o(testDF)))
## 
  |                                                                       
  |                                                                 |   0%
  |                                                                       
  |=================================================================| 100%
## 
  |                                                                       
  |                                                                 |   0%
  |                                                                       
  |=================================================================| 100%
str(pred)
## 'data.frame':    106 obs. of  1 variable:
##  $ predict: num  30.6 19.7 18.1 17.9 18.5 ...
plot(testDF$medv,pred$predict)
abline(0,1,col='black')