-
Notifications
You must be signed in to change notification settings - Fork 3
/
DeepLearning_GridSearch.R
83 lines (71 loc) · 2.88 KB
/
DeepLearning_GridSearch.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#=============================================================
# Load required packages
#=============================================================
require(ggplot2)
require(h2o)
source("plot_h2o_grid.R")
#=============================================================
# Init H2O (connect to a running H2O cluster)
#=============================================================
h2o.init(port = 54321)
#=============================================================
# Load data
#=============================================================
data_frame <-
h2o.importFile(
path = "http://www.dataminingconsultant.com/data/churn.txt",
sep = ",",
destination_frame = "data_frame")
colnames(data_frame) <- gsub(" ", "_", trimws(gsub("[[:punct:]]", " ", names(data_frame))))
#=============================================================
# Force classification
#=============================================================
data_frame$Churn <- as.factor(data_frame$Churn)
#=============================================================
# Split data into training and validation
#=============================================================
split_df <- h2o.splitFrame(data_frame, 0.7,
destination_frames = c("train_frame","valid_frame"),
seed=2016)
train_frame <- split_df[[1]]
valid_frame <- split_df[[2]]
#=============================================================
# Build the model
#=============================================================
y <- "Churn"
x <- setdiff(names(data_frame), y)
dl.grid <- h2o.grid(
algorithm = "deeplearning",
grid_id = "dl.grid.search",
x = x,
y = y,
training_frame = train_frame,
validation_frame = valid_frame,
hidden = c(100,100),
hidden_dropout_ratios = c(0.2,0.5),
loss = c("CrossEntropy"),
rate = 0.0001,
l1 = 0.0001,
l2 = 0.0001,
input_dropout_ratio = 0.1,
rate_annealing = 0.0001,
classification_stop = -1,
stopping_rounds = 1000,
score_interval = 0.0001,
balance_classes = TRUE,
hyper_params = list(
activation = c("RectifierWithDropout", "TanhWithDropout"),
epochs = c(500,1000),
rho = c(0.999,0.99),
epsilon = c(1e-11,1e-7)
))
dl.grid
#=============================================================
# Plot
#=============================================================
plotGridHistory(grid_id = "dl.grid.search",
score = "rmse",
history_messure = "epochs",
fname = "dl_grid_search.pdf",
y_lim = c(0,0.3),
x_lim = c(0,1000))