set.seed(1024)
01/06/2020
set.seed(1024)
library(ggplot2) library(nnet) library(bit64) library(h2o)
linear computation using the input values \[in_i = \sum_{i=1}^{k}{w_{i,j}a_i}\]
a non-linear (activation) function
output sent to other neurons
Feed-forward Artificial Neural Network
nnet
included in base installation
RSNNS
(Bergmeir and Benitez, 2012)FCNN4R
(Klima, 2016)neuralnet
(Fritsch et al., 2012)data(iris) rndSample <- sample(1:nrow(iris), 100) tr <- iris[rndSample, ] ts <- iris[-rndSample, ] n <- nnet(Species ~ ., tr, size = 6 ,trace = FALSE, maxit = 1000) ps <- predict(n, ts, type="class") (cm <- table(ps, ts$Species))
## ## ps setosa versicolor virginica ## setosa 12 0 0 ## versicolor 1 20 0 ## virginica 0 1 16
decay
can be used to set the learning ratedata(Boston,package='MASS') sp <- sample(1:nrow(Boston),354) tr <- Boston[sp,] ts <- Boston[-sp,] nr <- nnet(medv ~ ., tr, linout=TRUE, trace=FALSE, size=6, decay=0.01, maxit=2000) psnr <- predict(nr, ts) mean(abs(psnr-ts$medv))
## [1] 3.198552
plot(ts$medv, psnr) abline(0, 1)
h2o
(Aiello et al., 2016)mxnet
darch
(Drees, 2013)deepnet
(Rong, 2014)h2oInstance <- h2o.init(ip = "localhost") # start H2O instance locally
## ## H2O is not running yet, starting it now... ## ## Note: In case of errors look at the following log files: ## /tmp/RtmphH8qFr/filecd5c7a5a11e5/h2o_bgenc_started_from_r.out ## /tmp/RtmphH8qFr/filecd5c2dc88072/h2o_bgenc_started_from_r.err ## ## ## Starting H2O JVM and connecting: . Connection successful! ## ## R is connected to the H2O cluster: ## H2O cluster uptime: 1 seconds 106 milliseconds ## H2O cluster timezone: Europe/Istanbul ## H2O data parsing timezone: UTC ## H2O cluster version: 3.30.0.1 ## H2O cluster version age: 1 month and 28 days ## H2O cluster name: H2O_started_from_R_bgenc_qbt439 ## H2O cluster total nodes: 1 ## H2O cluster total memory: 3.88 GB ## H2O cluster total cores: 12 ## H2O cluster allowed cores: 12 ## 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, XGBoost, Algos, AutoML, Core V3, TargetEncoder, Core V4 ## R Version: R version 4.0.0 (2020-04-24)
rndSample <- sample(1:nrow(iris), 100) trH <- as.h2o(iris[rndSample, ], "trH") tsH <- as.h2o(iris[-rndSample, ], "tsH") mdl <- h2o.deeplearning(x = 1:4, y = 5, training_frame = trH) preds <- h2o.predict(mdl, tsH)[, "predict"]
(cm <- table(as.vector(preds), as.vector(tsH$Species)))
## ## setosa versicolor virginica ## setosa 16 0 0 ## versicolor 0 15 0 ## virginica 0 5 14
data(Boston, package="MASS") trH <- as.h2o(Boston[sp, ],"trH") tsH <- as.h2o(Boston[-sp, ],"tsH") mdl <- h2o.deeplearning(x=1:13, y=14, training_frame=trH, hidden = c(100, 100, 100, 100), epochs = 500) preds <- as.vector(h2o.predict(mdl,tsH))
mean(abs(preds - as.vector(tsH$medv)))
## [1] 2.339476
plot(as.vector(tsH$medv), preds) abline(0, 1)
plot(as.vector(tsH$medv), preds) points(as.vector(tsH$medv), psnr, col = "red") abline(0, 1)