Learn R Programming

sits (version 1.5.3)

sits_tuning: Tuning machine learning models hyper-parameters

Description

This function performs a random search on values of selected hyperparameters, and produces a data frame with the accuracy and kappa values produced by a validation procedure. The result allows users to select appropriate hyperparameters for deep learning models.

Usage

sits_tuning(
  samples,
  samples_validation = NULL,
  validation_split = 0.2,
  ml_method = sits_tempcnn(),
  params = sits_tuning_hparams(optimizer = torch::optim_adamw, opt_hparams = list(lr =
    loguniform(0.01, 1e-04))),
  trials = 30L,
  multicores = 2L,
  gpu_memory = 4L,
  batch_size = 2L^gpu_memory,
  progress = FALSE
)

Value

A tibble containing all parameters used to train on each trial ordered by accuracy.

Arguments

samples

Time series set to be validated.

samples_validation

Time series set used for validation.

validation_split

Percent of original time series set to be used for validation (if samples_validation is NULL)

ml_method

Machine learning method.

params

List with hyper parameters to be passed to ml_method. User can use uniform, choice, randint, normal, lognormal, loguniform, and beta distribution functions to randomize parameters.

trials

Number of random trials to perform the search.

multicores

Number of cores to process in parallel.

gpu_memory

Memory available in GPU in GB (default = 4)

batch_size

Batch size for GPU classification.

progress

Show progress bar?

Author

Rolf Simoes, rolfsimoes@gmail.com

References

James Bergstra, Yoshua Bengio, "Random Search for Hyper-Parameter Optimization". Journal of Machine Learning Research. 13: 281–305, 2012.

Examples

Run this code
if (sits_run_examples()) {
    # find best learning rate parameters for TempCNN
    tuned <- sits_tuning(
        samples_modis_ndvi,
        ml_method = sits_tempcnn(),
        params = sits_tuning_hparams(
            optimizer = choice(
                torch::optim_adamw
            ),
            opt_hparams = list(
                lr = loguniform(10^-2, 10^-4)
            )
        ),
        trials = 4,
        multicores = 2,
        progress = FALSE
    )
    # obtain best accuracy, kappa and best_lr
    accuracy <- tuned$accuracy[[1]]
    kappa <- tuned$kappa[[1]]
    best_lr <- tuned$opt_hparams[[1]]$lr
}

Run the code above in your browser using DataLab