
Hyperparameter tuning by grid or random search (Geron Ch 1, morie.fn hmhpt)
Source:R/geron_w4b_native.R
morie_geron_hyperparameter_tuning.RdThe grid branch is exact and deterministic (delegates to the existing morie_geron_cross_validation_score core). The random branch's candidate draws use the shared LCG stream, not numpy's PCG64 – non-portable.
Usage
morie_geron_hyperparameter_tuning(
param_grid,
X,
y,
estimator = NULL,
search = "grid",
n_iter = 10,
K = 3,
seed = 0,
score = NULL
)Value
List with best_params, best_score, results, n_candidates, n_fits, distinct_values_per_param, estimate, n, method.
Examples
X <- matrix(c(1, 2, 3, 4), ncol = 1)
y <- c(3, 6, 9, 12)
morie_geron_hyperparameter_tuning(list(alpha = c(0, 1, 100)),
X, y, K = 2)
#> $best_params
#> $best_params$alpha
#> [1] 0
#>
#>
#> $best_score
#> [1] 1
#>
#> $results
#> $results[[1]]
#> $results[[1]]$params
#> $results[[1]]$params$alpha
#> [1] 0
#>
#>
#> $results[[1]]$cv_score
#> [1] 1
#>
#> $results[[1]]$fold_scores
#> [1] 1 1
#>
#>
#> $results[[2]]
#> $results[[2]]$params
#> $results[[2]]$params$alpha
#> [1] 1
#>
#>
#> $results[[2]]$cv_score
#> [1] 0.2981591
#>
#> $results[[2]]$fold_scores
#> [1] 0.9852071 -0.3888889
#>
#>
#> $results[[3]]
#> $results[[3]]$params
#> $results[[3]]$params$alpha
#> [1] 100
#>
#>
#> $results[[3]]$cv_score
#> [1] -24.87574
#>
#> $results[[3]]$fold_scores
#> [1] -5.40000 -44.35147
#>
#>
#>
#> $n_candidates
#> [1] 3
#>
#> $n_fits
#> [1] 6
#>
#> $estimate
#> [1] 1
#>
#> $n
#> [1] 4
#>
#> $method
#> [1] "Hyperparameter tuning by grid or random search"
#>
#> $distinct_values_per_param
#> $distinct_values_per_param$alpha
#> [1] 3
#>
#>
#> $search
#> [1] "grid"
#>