Closed andrjohns closed 4 years ago
The range of lambda
is data-driven and is affected by the choice of alpha
. For that reason (and a few others), we use a default range of:
> penalty()
Amount of Regularization (quantitative)
Transformer: log-10
Range (transformed scale): [-10, 0]
which works well in 99% of the cases.
You can change the range if you need to go higher:
library(tidymodels)
#> ── Attaching packages ────────────────────────────────────────── tidymodels 0.1.1 ──
#> ✓ broom 0.7.0 ✓ recipes 0.1.13
#> ✓ dials 0.0.8.9000 ✓ rsample 0.0.7
#> ✓ dplyr 1.0.2 ✓ tibble 3.0.3
#> ✓ ggplot2 3.3.2 ✓ tidyr 1.1.2
#> ✓ infer 0.5.2 ✓ tune 0.1.1.9000
#> ✓ modeldata 0.0.2 ✓ workflows 0.1.3
#> ✓ parsnip 0.1.3.9000 ✓ yardstick 0.0.7
#> ✓ purrr 0.3.4
#> ── Conflicts ───────────────────────────────────────────── tidymodels_conflicts() ──
#> x purrr::discard() masks scales::discard()
#> x dplyr::filter() masks stats::filter()
#> x dplyr::lag() masks stats::lag()
#> x recipes::step() masks stats::step()
mod <-
linear_reg(mode = "regression", penalty = tune(), mixture = 0) %>%
set_engine("glmnet")
mod %>%
parameters() %>%
update(penalty = penalty(log10(c(0.02, 198)))) %>%
grid_regular(levels = 10) %>%
summary()
#> penalty
#> Min. : 0.0200
#> 1st Qu.: 0.2232
#> Median : 2.2556
#> Mean : 30.9259
#> 3rd Qu.: 21.5277
#> Max. :198.0000
Created on 2020-09-08 by the reprex package (v0.3.0)
(this also works with the CRAN versions of these packages; the versions above are what I have currently installed)
Excellent, thanks for the help Max!
This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.
Hi,
I'm trying to use the
tidymodels
ecosystem to run a ridge regression, and so am using thegrid_regular
function to create the search space oflambda
values to evaluate. However, these lambda values are always upper-bounded by 1, and when I run some data throughcv.glmnet
, thelambda
s tested and chosen are greater than one:Created on 2020-09-08 by the reprex package (v0.3.0)
Should I be using this functionality differently for ridge regression?