library(h2o)
setwd("~/tjo.hatenablog.samples-master/r_samples/public_lib/jp/exp_uci_datasets/card_approval")
localH2O <- h2o.init(ip = "localhost", port = 54321, startH2O = TRUE, nthreads=-1)
train_data <- h2o.importFile(localH2O, path = "card_train.csv")
test_data <- h2o.importFile(localH2O, path = "card_test.csv")
# Deep Learningによる学習と予測
h2o.dp <- function(activation) {
res.dl <- h2o.deeplearning(x = 1:15, y = 16, training_frame = train_data, activation = activation, hidden=c(100, 100, 200), epochs=200, fast_mode = TRUE)
pred.dl <- h2o.predict(object=res.dl, newdata=test_data[,-16])
pred.dl.df <- as.data.frame(pred.dl)
test_data.df <- as.data.frame(test_data)
sum(ifelse(pred.dl.df [,1] == test_data.df[,16],0,1))
# 結果の格納-正解なら0, 不正解なら1の値が入る
error_num <- sum(ifelse(pred.dl.df [,1] == test_data.df[,16],0,1))
error_rate <- (error_num / nrow(pred.dl.df))*100
print(paste("Rate of Error: ", round(error_rate, 2), " %"))
#result
round(error_rate, 2)
}
Deep_Learn_RD <- h2o.dp("RectifierWithDropout")
Deep_Learn_R <- h2o.dp("Rectifier")
Deep_Learn_TD <- h2o.dp("TanhWithDropout")
Deep_Learn_T <- h2o.dp("Tanh")
Deep_Learn_MD <- h2o.dp("MaxoutWithDropout")
Deep_Learn_M <- h2o.dp("Maxout")
Deep_Learn_RD #16
Deep_Learn_R #19
Deep_Learn_TD #18
Deep_Learn_T #20
Deep_Learn_MD #12
Deep_Learn_M #18
h2o.shutdown(localH2O)