Last active
January 22, 2016 08:48
-
-
Save ethen8181/176183b53c0417760f95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(data.table) | |
ids <- grid@model_ids | |
BestGridSearch <- function( ids ) | |
{ | |
# ------------------------------------------------------------------ | |
# Description : | |
# Pass in a list of h2o model id obtained by h2o.grid | |
# and returns the best model its classification error | |
# | |
# Args : | |
# @ids = a list indicating the unique model id of the model to retrieve | |
# | |
# Values : | |
# A list containing the slot best_model and best_error | |
# | |
# ------------------------------------------------------------------ | |
# obtain the confusion matrix and return the last error for every id | |
error <- vapply( ids, function(x) | |
{ | |
cm <- h2o.getModel(ids[[1]]) %>% | |
h2o.performance( valid = TRUE ) %>% | |
h2o.confusionMatrix() | |
return( cm$Error[ length(cm$Error) ] ) | |
}, numeric(1) ) | |
# a data.table with two columns : | |
# the model and its corresponding error | |
# sorted ascendingly by error | |
scores <- data.table( | |
model = unlist(ids), | |
error = error | |
)[ order(error) ] | |
# different slots for obtaining its parameters and all its parameters | |
# best_model@parameters | |
# best_model@allparameters | |
return( list( best_model = h2o.getModel( scores$model[1] ), | |
best_error = scores$error[1] ) ) | |
} | |
model_best_grid <- BestGridSearch( ids = ids ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment