Skip to content

Instantly share code, notes, and snippets.

@sriyoda
Created April 12, 2016 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sriyoda/8cab635c1f7457474b5028acc2f15f37 to your computer and use it in GitHub Desktop.
Save sriyoda/8cab635c1f7457474b5028acc2f15f37 to your computer and use it in GitHub Desktop.
#Random hyper parameter search
models <- c()
for (i in 1:20) {
rand_activation <- c("TanhWithDropout", "RectifierWithDropout")[sample(1:2,1)]
rand_numlayers <- sample(2:5,1)
rand_hidden <- c(sample(10:50,rand_numlayers,T))
rand_l1 <- runif(1, 0, 1e-3)
rand_l2 <- runif(1, 0, 1e-3)
rand_dropout <- c(runif(rand_numlayers, 0, 0.6))
rand_input_dropout <- runif(1, 0, 0.5)
dlmodel <- h2o.deeplearning(
x = 1:369, y = 371,
training_frame = train_holdout.hex,
validation_frame = valid_holdout.hex,
epochs=1,
stopping_metric="misclassification",
stopping_tolerance=1e-2, ## stop when logloss does not improve by >=1% for 2 scoring events
stopping_rounds=2,
score_validation_samples=10000, ## downsample validation set for faster scoring
score_duty_cycle=0.025, ## don't score more than 2.5% of the wall time
max_w2=10, ## can help improve stability for Rectifier
### Random parameters
activation=rand_activation,
hidden=rand_hidden,
l1=rand_l1, l2=rand_l2,
input_dropout_ratio=rand_input_dropout,
hidden_dropout_ratios=rand_dropout
)
models <- c(models, dlmodel)
}
# Find the best model (lowest mse on the validation holdout set)
base_auc <- 0.5
for (i in 1:length(models)) {
auc <- h2o.auc( h2o.performance(models[[i]], valid_holdout.hex))
if (auc > base_auc) {
base_auc <- auc
best_model <- models[[i]]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment