The function performs a random search in the hyperparameters space, creating a population of random models each one with a random combination of the provided hyperparameters values.

randomSearch(
  model,
  hypers,
  metric,
  test = NULL,
  pop = 20,
  env = NULL,
  seed = NULL
)

Arguments

model

SDMmodel or SDMmodelCV object.

hypers

named list containing the values of the hyperparameters that should be tuned, see details.

metric

character. The metric used to evaluate the models, possible values are: "auc", "tss" and "aicc".

test

SWD object. Test dataset used to evaluate the model, not used with aicc and SDMmodelCV objects, default is NULL.

pop

numeric. Size of the population, default is 20.

env

stack containing the environmental variables, used only with "aicc", default is NULL.

seed

numeric. The value used to set the seed to have consistent results, default is NULL.

Value

SDMtune object.

Details

  • To know which hyperparameters can be tuned you can use the output of the function getTunableArgs. Hyperparameters not included in the hypers argument take the value that they have in the passed model.

Author

Sergio Vignali

Examples

# \donttest{ # Acquire environmental variables files <- list.files(path = file.path(system.file(package = "dismo"), "ex"), pattern = "grd", full.names = TRUE) predictors <- raster::stack(files) # Prepare presence and background locations p_coords <- virtualSp$presence bg_coords <- virtualSp$background # Create SWD object data <- prepareSWD(species = "Virtual species", p = p_coords, a = bg_coords, env = predictors, categorical = "biome")
#> Extracting predictor information for presence locations...
#> Extracting predictor information for absence/background locations...
# Split presence locations in training (80%) and testing (20%) datasets datasets <- trainValTest(data, test = 0.2, only_presence = TRUE) train <- datasets[[1]] test <- datasets[[2]] # Train a model model <- train(method = "Maxnet", data = train, fc = "l") # Define the hyperparameters to test h <- list(reg = seq(0.2, 3, 0.2), fc = c("lqp", "lqph", "lh")) # Run the function using as metric the AUC output <- randomSearch(model, hypers = h, metric = "auc", test = test, pop = 10, seed = 25) output@results
#> fc reg train_AUC test_AUC diff_AUC #> 1 lqp 0.2 0.8683369 0.8452413 0.02309562 #> 2 lqp 0.6 0.8667788 0.8447712 0.02200750 #> 3 lqp 1.2 0.8649231 0.8442637 0.02065938 #> 4 lqp 1.8 0.8626844 0.8433263 0.01935812 #> 5 lqph 0.6 0.8774013 0.8422513 0.03515000 #> 6 lqph 1.8 0.8686994 0.8387788 0.02992063 #> 7 lh 1.6 0.8671119 0.8378788 0.02923312 #> 8 lqph 2.0 0.8674688 0.8377488 0.02972000 #> 9 lqph 2.8 0.8639156 0.8366712 0.02724437 #> 10 lh 2.4 0.8626194 0.8358887 0.02673063
output@models
#> [[1]] #> Object of class SDMmodel #> Method: Maxnet #> #> Species: Virtual species #> Presence locations: 320 #> Absence locations: 5000 #> #> Model configurations: #> -------------------- #> fc: lqp #> reg: 0.2 #> #> Variables: #> --------- #> Continuous: bio1 bio12 bio16 bio17 bio5 bio6 bio7 bio8 #> Categorical: biome #> [[2]] #> Object of class SDMmodel #> Method: Maxnet #> #> Species: Virtual species #> Presence locations: 320 #> Absence locations: 5000 #> #> Model configurations: #> -------------------- #> fc: lqp #> reg: 0.6 #> #> Variables: #> --------- #> Continuous: bio1 bio12 bio16 bio17 bio5 bio6 bio7 bio8 #> Categorical: biome #> [[3]] #> Object of class SDMmodel #> Method: Maxnet #> #> Species: Virtual species #> Presence locations: 320 #> Absence locations: 5000 #> #> Model configurations: #> -------------------- #> fc: lqp #> reg: 1.2 #> #> Variables: #> --------- #> Continuous: bio1 bio12 bio16 bio17 bio5 bio6 bio7 bio8 #> Categorical: biome #> [[4]] #> Object of class SDMmodel #> Method: Maxnet #> #> Species: Virtual species #> Presence locations: 320 #> Absence locations: 5000 #> #> Model configurations: #> -------------------- #> fc: lqp #> reg: 1.8 #> #> Variables: #> --------- #> Continuous: bio1 bio12 bio16 bio17 bio5 bio6 bio7 bio8 #> Categorical: biome #> [[5]] #> Object of class SDMmodel #> Method: Maxnet #> #> Species: Virtual species #> Presence locations: 320 #> Absence locations: 5000 #> #> Model configurations: #> -------------------- #> fc: lqph #> reg: 0.6 #> #> Variables: #> --------- #> Continuous: bio1 bio12 bio16 bio17 bio5 bio6 bio7 bio8 #> Categorical: biome #> [[6]] #> Object of class SDMmodel #> Method: Maxnet #> #> Species: Virtual species #> Presence locations: 320 #> Absence locations: 5000 #> #> Model configurations: #> -------------------- #> fc: lqph #> reg: 1.8 #> #> Variables: #> --------- #> Continuous: bio1 bio12 bio16 bio17 bio5 bio6 bio7 bio8 #> Categorical: biome #> [[7]] #> Object of class SDMmodel #> Method: Maxnet #> #> Species: Virtual species #> Presence locations: 320 #> Absence locations: 5000 #> #> Model configurations: #> -------------------- #> fc: lh #> reg: 1.6 #> #> Variables: #> --------- #> Continuous: bio1 bio12 bio16 bio17 bio5 bio6 bio7 bio8 #> Categorical: biome #> [[8]] #> Object of class SDMmodel #> Method: Maxnet #> #> Species: Virtual species #> Presence locations: 320 #> Absence locations: 5000 #> #> Model configurations: #> -------------------- #> fc: lqph #> reg: 2 #> #> Variables: #> --------- #> Continuous: bio1 bio12 bio16 bio17 bio5 bio6 bio7 bio8 #> Categorical: biome #> [[9]] #> Object of class SDMmodel #> Method: Maxnet #> #> Species: Virtual species #> Presence locations: 320 #> Absence locations: 5000 #> #> Model configurations: #> -------------------- #> fc: lqph #> reg: 2.8 #> #> Variables: #> --------- #> Continuous: bio1 bio12 bio16 bio17 bio5 bio6 bio7 bio8 #> Categorical: biome #> [[10]] #> Object of class SDMmodel #> Method: Maxnet #> #> Species: Virtual species #> Presence locations: 320 #> Absence locations: 5000 #> #> Model configurations: #> -------------------- #> fc: lh #> reg: 2.4 #> #> Variables: #> --------- #> Continuous: bio1 bio12 bio16 bio17 bio5 bio6 bio7 bio8 #> Categorical: biome
# Order results by highest test AUC output@results[order(-output@results$test_AUC), ]
#> fc reg train_AUC test_AUC diff_AUC #> 1 lqp 0.2 0.8683369 0.8452413 0.02309562 #> 2 lqp 0.6 0.8667788 0.8447712 0.02200750 #> 3 lqp 1.2 0.8649231 0.8442637 0.02065938 #> 4 lqp 1.8 0.8626844 0.8433263 0.01935812 #> 5 lqph 0.6 0.8774013 0.8422513 0.03515000 #> 6 lqph 1.8 0.8686994 0.8387788 0.02992063 #> 7 lh 1.6 0.8671119 0.8378788 0.02923312 #> 8 lqph 2.0 0.8674688 0.8377488 0.02972000 #> 9 lqph 2.8 0.8639156 0.8366712 0.02724437 #> 10 lh 2.4 0.8626194 0.8358887 0.02673063
# }