View source: R/hmda.best.models.R
| hmda.best.models | R Documentation |
Scans an HMDA grid analysis data frame for performance metric columns and, for each metric, selects the best-performing models according to the correct optimization direction (lower is better for some metrics; higher is better for others). The function returns a subset of the input data frame containing the union of selected model IDs.
hmda.best.models(
df,
n_models = NULL,
distance_percentage = NULL,
metrics = c("logloss", "mae", "mse", "rmse", "rmsle", "mean_per_class_error", "auc",
"aucpr", "r2", "accuracy", "f1", "mcc", "f2"),
hyperparam = FALSE
)
df |
A data frame of class |
n_models |
Integer. The number of top models to select per metric.
If both |
distance_percentage |
Numeric in (0, 1). Alternative to |
metrics |
Character vector of performance metric column names to consider. Supported metrics are "logloss", "mae", "mse", "rmse", "rmsle", "mean_per_class_error", "auc", "aucpr", "r2", "accuracy", "f1", "mcc", "f2". |
hyperparam |
Logical. If |
The function uses a predefined set of H2O performance metrics along with their desired optimization directions:
Lower values are better.
Higher values are better.
A data frame containing the union of selected models across all considered metrics.
If hyperparam = FALSE, the output includes model_ids and the metric columns found in df.
If hyperparam = TRUE, the output includes all columns from df for the selected models.
E. F. Haghish
## Not run:
library(HMDA)
library(h2o)
hmda.init()
# Import a sample binary outcome dataset into H2O
train <- h2o.importFile(
"https://s3.amazonaws.com/h2o-public-test-data/smalldata/higgs/higgs_train_10k.csv")
test <- h2o.importFile(
"https://s3.amazonaws.com/h2o-public-test-data/smalldata/higgs/higgs_test_5k.csv")
# Identify predictors and response
y <- "response"
x <- setdiff(names(train), y)
# For binary classification, response should be a factor
train[, y] <- as.factor(train[, y])
test[, y] <- as.factor(test[, y])
params <- list(learn_rate = c(0.01, 0.1),
max_depth = c(3, 5, 9),
sample_rate = c(0.8, 1.0)
)
# Train and validate a cartesian grid of GBMs
hmda_grid1 <- hmda.grid(algorithm = "gbm", x = x, y = y,
grid_id = "hmda_grid1",
training_frame = train,
nfolds = 10,
ntrees = 100,
seed = 1,
hyper_params = params)
# Assess the performances of the models
grid_performance <- hmda.grid.analysis(hmda_grid1)
# Return the best 2 models according to each metric
hmda.best.models(grid_performance, n_models = 2)
# return all models with performance metric as high as 98\
# i.e., the distance of the selected models should be up to 2\
# best model in each metric
hmda.best.models(grid_performance, distance_percentage = 0.02)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.