
extractPath
extractPath.RdExtracts the coefficient path of the elastic net
Usage
extractPath(model, ...)
# S3 method for glmnet
extractPath(model, intercept = FALSE, ...)
# S3 method for cv.glmnet
extractPath(model, ...)Arguments
- model
A
glmnetmodel- ...
Further arguments
- intercept
If
FALSE(the default), no intercept will be provided
Details
This is a replacement plot for visualizing the coefficient path resulting from the elastic net.
Examples
library(glmnet)
data(diamonds, package='ggplot2')
diaX <- useful::build.x(price ~ carat + cut + x - 1, data=diamonds, contrasts = TRUE)
diaY <- useful::build.y(price ~ carat + cut + x - 1, data=diamonds)
modG1 <- glmnet(x=diaX, y=diaY)
extractPath(modG1)
#> # A tibble: 79 × 8
#> lambda carat cutFair cutGood `cutVery Good` cutPremium cutIdeal x
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 0.953 10054. -1511. -354. 22.6 -4.64 319. -951.
#> 2 1.05 10034. -1509. -354. 21.5 -5.10 318. -942.
#> 3 1.14 10011. -1508. -354. 20.2 -5.60 317. -933.
#> 4 1.23 9985. -1506. -354. 18.9 -6.16 316. -922.
#> 5 1.33 9955. -1504. -354. 17.5 -6.77 314. -909.
#> 6 1.42 9924. -1502. -353. 16.0 -7.29 313. -896.
#> 7 1.51 9890. -1499. -353. 14.5 -7.78 312. -882.
#> 8 1.60 9852. -1497. -352. 12.9 -8.24 310. -866.
#> 9 1.70 9809. -1493. -351. 11.3 -8.67 309. -848.
#> 10 1.79 9765. -1490. -350. 9.69 -8.91 307. -830.
#> # ℹ 69 more rows
modG2 <- cv.glmnet(x=diaX, y=diaY, nfolds=5)
extractPath(modG2)
#> # A tibble: 79 × 8
#> lambda carat cutFair cutGood `cutVery Good` cutPremium cutIdeal x
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 0.953 10054. -1511. -354. 22.6 -4.64 319. -951.
#> 2 1.05 10034. -1509. -354. 21.5 -5.10 318. -942.
#> 3 1.14 10011. -1508. -354. 20.2 -5.60 317. -933.
#> 4 1.23 9985. -1506. -354. 18.9 -6.16 316. -922.
#> 5 1.33 9955. -1504. -354. 17.5 -6.77 314. -909.
#> 6 1.42 9924. -1502. -353. 16.0 -7.29 313. -896.
#> 7 1.51 9890. -1499. -353. 14.5 -7.78 312. -882.
#> 8 1.60 9852. -1497. -352. 12.9 -8.24 310. -866.
#> 9 1.70 9809. -1493. -351. 11.3 -8.67 309. -848.
#> 10 1.79 9765. -1490. -350. 9.69 -8.91 307. -830.
#> # ℹ 69 more rows