Native k-fold cross-validated random search: n_iter candidate
hyperparameter settings are drawn at random (caret's random-search
distributions: alpha ~ U(0, 1), lambda = 2^U(-10, 3) for
"glmnet"; lambda = 10^U(-5, 1) for "ridge"), each is
scored by cross-validation with rmorie's own learners, and the best is
returned. Folds, metrics, tie-breaking and the supported learners
("lm", "glm", "glmnet", "ridge") are those of
morie_grid_search_cv(), which documents them; the RNG protocol is
caret's train(search = "random"): one draw seeds the
(isolated) fold assignment, then the candidates are drawn from the
main stream, so a given seed reproduces caret's candidates and folds.
Usage
morie_random_search_cv(
x,
y,
method = NULL,
n_iter = 20L,
cv = 5L,
task = "auto",
seed = 0L,
deterministic_seed = NULL
)Arguments
- x
Numeric predictor matrix.
- y
Response.
- method
Learner id, one of
"lm","glm","glmnet","ridge"(default"glmnet"for classification,"ridge"for regression).- n_iter
Number of random draws.
- cv
CV folds.
- task
"auto" / "classification" / "regression".
- seed
RNG seed.
- deterministic_seed
Integer or NULL. If supplied, the RNG state is derived from the SHA-keyed
morie_det_rng()so Py<->R streams agree on the canonical fixture. WhenNULL(default), behaviour is unchanged:seeddrivesset.seed()directly.
Value
Named list: estimate (CV score of the best draw), best_params, best_score (same as estimate), sampled_params (the drawn parameters, sorted, with the fold standard deviations of the metrics), sampled_scores (mean CV RMSE for regression, accuracy for classification, aligned with sampled_params), n_iter, task, n, method.
Examples
set.seed(1)
x <- matrix(rnorm(120), 40, 3)
y <- drop(x %*% c(1, -0.5, 0)) + rnorm(40)
morie_random_search_cv(x, y, n_iter = 4L, cv = 3L, task = "regression")
#> $estimate
#> [1] 0.9549318
#>
#> $best_params
#> $best_params$lambda
#> [1] 2.813499
#>
#>
#> $best_score
#> [1] 0.9549318
#>
#> $sampled_params
#> lambda RMSESD RsquaredSD MAESD
#> 1 0.0001622152 0.10496248 0.05806580 0.08892095
#> 2 0.0017090053 0.10411330 0.05809362 0.08869571
#> 3 0.0273602575 0.09276388 0.05871163 0.08608925
#> 4 2.8134988370 0.19278543 0.10883596 0.21221732
#>
#> $sampled_scores
#> [1] 0.9696466 0.9691100 0.9610609 0.9549318
#>
#> $n_iter
#> [1] 4
#>
#> $task
#> [1] "regression"
#>
#> $n
#> [1] 40
#>
#> $method
#> [1] "Random search CV (ridge)"
#>
