library(tidyverse); library(mgcv); library(mgcViz); library(janitor); library(tidymodels)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5     ✓ purrr   0.3.4
## ✓ tibble  3.1.6     ✓ dplyr   1.0.7
## ✓ tidyr   1.1.4     ✓ stringr 1.4.0
## ✓ readr   2.1.0     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
## Loading required package: nlme
## 
## Attaching package: 'nlme'
## The following object is masked from 'package:dplyr':
## 
##     collapse
## This is mgcv 1.8-38. For overview type 'help("mgcv-package")'.
## Loading required package: qgam
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
## Registered S3 method overwritten by 'mgcViz':
##   method from  
##   +.gg   GGally
## 
## Attaching package: 'mgcViz'
## The following objects are masked from 'package:stats':
## 
##     qqline, qqnorm, qqplot
## 
## Attaching package: 'janitor'
## The following objects are masked from 'package:stats':
## 
##     chisq.test, fisher.test
## Registered S3 method overwritten by 'tune':
##   method                   from   
##   required_pkgs.model_spec parsnip
## ── Attaching packages ────────────────────────────────────── tidymodels 0.1.4 ──
## ✓ broom        0.7.10     ✓ rsample      0.1.1 
## ✓ dials        0.0.10     ✓ tune         0.1.6 
## ✓ infer        1.0.0      ✓ workflows    0.2.4 
## ✓ modeldata    0.1.1      ✓ workflowsets 0.1.0 
## ✓ parsnip      0.1.7      ✓ yardstick    0.0.9 
## ✓ recipes      0.1.17
## ── Conflicts ───────────────────────────────────────── tidymodels_conflicts() ──
## x recipes::check()  masks qgam::check()
## x nlme::collapse()  masks dplyr::collapse()
## x scales::discard() masks purrr::discard()
## x dplyr::filter()   masks stats::filter()
## x recipes::fixed()  masks stringr::fixed()
## x dplyr::lag()      masks stats::lag()
## x yardstick::spec() masks readr::spec()
## x recipes::step()   masks stats::step()
## • Use suppressPackageStartupMessages() to eliminate package startup messages
library(skimr); library(ggmap); library(vip)
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
## 
## Attaching package: 'vip'
## The following object is masked from 'package:utils':
## 
##     vi
d <- readRDS("~/Dropbox/Mac (2)/Desktop/aru-projects/sd_data.rds")
tidymodels_prefer()

glimpse(d)
## Rows: 4,306
## Columns: 11
## $ rID                    <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, …
## $ lc1990                 <dbl> 21, 3, 4, 21, 4, 4, 4, 3, 4, 3, 4, 3, 20, 3, 4,…
## $ lc2000                 <dbl> 7, 3, 3, 7, 3, 4, 3, 3, 4, 3, 4, 1, 7, 3, 4, 1,…
## $ lc2015                 <dbl> 10, 1, 4, 10, 4, 4, 3, 3, 4, 3, 4, 4, 10, 3, 4,…
## $ bt                     <dbl> 603.0000, 1194.0000, 1251.2693, 575.7488, 269.5…
## $ gsw                    <dbl> 1072.00000, 1147.00000, 1265.49651, 764.46792, …
## $ meantemp               <dbl> 93.43246, 95.09166, 94.10497, 91.58929, 97.1954…
## $ diurnal_range          <dbl> 72.99537, 72.97844, 74.00000, 75.80238, 62.0000…
## $ min_temp_coldest_month <dbl> 5.4324588, 8.1833136, -3.1581891, 0.5902241, 15…
## $ presence               <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
## $ coords                 <dbl[,3]> <matrix[26 x 3]>

Code book

  • lc1990 21 category landcover - dominant class
  • lc2000, lc2000 10 category landcover - dominant class per km2
  • lc2015, lc2015 10 category landcover - dominant class per km2
  • bt blue tit hectad counts (observations per km2)
  • gsw great spotted woodpecker hectad counts (observations per km2)
  • meantemp mean temp across year C
  • diurnal_range mean daily variation C
  • min_temp_coldest min temp on coldest day C
  • presence presence/ pseudo-absence willow tit (estimated by random sampling background as part of sdmData preparation)
  • rID row ID
  • coords x y coordinates in metres

Convert outcome to factor and extract x, y variavles

d_1 <- d %>%
  mutate(presence = factor(presence), 
         coords1 = data.frame(coords), 
         x = coords1[, 2],
         y = coords1[, 3])

d_1 <- d_1 %>%
  select(-c(rID, coords, coords1)) 

d_1 %>%
  head()

Split data and create validation dataset

d_split <- initial_split(d_1, strata = presence)
d_train <- training(d_split)
d_test <- testing(d_split)

val_set <- validation_split(d_train, 
                            strata = presence, 
                            prop = 0.80)
val_set

Create recipe (pre-processing)

wt_rec <- recipe(presence ~ bt + gsw + meantemp + diurnal_range + min_temp_coldest_month + lc1990 + lc2000 + lc2015 + x + y, data = d_train) %>%
  step_log(bt, base = 10) %>%
  step_log(gsw, base = 10) 

Create mod specs

glm <- 
  logistic_reg() %>%
  set_engine("glm") %>% 
  set_mode("classification")
  
lr_mod <- 
  logistic_reg(penalty = 1) %>% 
  set_engine("glmnet")

rf_mod <- 
  rand_forest(mtry = 1, min_n = 8, trees = 1000) %>% 
  set_engine("ranger", num.threads = 8, importance = "impurity") %>% 
  set_mode("classification")

resamples

wt_cv_folds <- bake(prep(wt_rec),
                    new_data = d_train) %>%
  rsample::vfold_cv(v = 5)

Fit models

glmw <- workflow() %>%
  add_model(glm) %>%
  add_recipe(wt_rec) 

glm_fit <- fit(glmw,  d_train)

glmnetw <- workflow() %>%
  add_model(lr_mod) %>%
  add_recipe(wt_rec) 

glmnet_fit <- fit(glmnetw,  d_train)

rfw <- workflow() %>%
  add_model(rf_mod) %>%
  add_recipe(wt_rec) 

rf_fit <- fit(rfw,  d_train)



## after Julia Silge

xgb_spec <- boost_tree(
  trees = 1000, 
  tree_depth = tune(), min_n = tune(), 
  loss_reduction = tune(),                     ## first three: model complexity
  sample_size = tune(), mtry = tune(),         ## randomness
  learn_rate = tune(),                         ## step size
) %>% 
  set_engine("xgboost") %>% 
  set_mode("classification")

xgb_spec
## Boosted Tree Model Specification (classification)
## 
## Main Arguments:
##   mtry = tune()
##   trees = 1000
##   min_n = tune()
##   tree_depth = tune()
##   learn_rate = tune()
##   loss_reduction = tune()
##   sample_size = tune()
## 
## Computational engine: xgboost
xgb_grid <- grid_latin_hypercube(
  
  tree_depth(),
  min_n(),
  loss_reduction(),
  sample_size = sample_prop(),
  finalize(mtry(), d_train),
  learn_rate(), 
  size = 30
)

xgb_grid
xgboost_wf <- workflow() %>%
  add_model(xgb_spec) %>%
  add_recipe(wt_rec)

set.seed(42)

vb_folds <- vfold_cv(d_train, strata = presence)

doParallel::registerDoParallel()
set.seed(12345)


xgb_res <- tune_grid(
  xgboost_wf,
  resamples = vb_folds, 
  grid = xgb_grid, 
  control  = control_grid(save_pred = TRUE)
  
)


collect_metrics(xgb_res)
xgb_res %>%
  collect_metrics() %>%
  filter(.metric == "roc_auc") %>%
  select(mean, mtry:sample_size) %>%
  pivot_longer(mtry:sample_size,
               values_to = "value",
               names_to = "parameter"
  ) %>%
  ggplot(aes(value, mean, color = parameter)) +
  geom_point(alpha = 0.8, show.legend = FALSE) +
  facet_wrap(~parameter, scales = "free_x") +
  labs(x = NULL, y = "AUC")

show_best(xgb_res, "roc_auc")
best_auc <- select_best(xgb_res, "roc_auc")
best_auc
final_xgb <- finalize_workflow(
  xgboost_wf,
  best_auc
)

final_xgb
## ══ Workflow ════════════════════════════════════════════════════════════════════
## Preprocessor: Recipe
## Model: boost_tree()
## 
## ── Preprocessor ────────────────────────────────────────────────────────────────
## 2 Recipe Steps
## 
## • step_log()
## • step_log()
## 
## ── Model ───────────────────────────────────────────────────────────────────────
## Boosted Tree Model Specification (classification)
## 
## Main Arguments:
##   mtry = 3
##   trees = 1000
##   min_n = 21
##   tree_depth = 6
##   learn_rate = 0.0044215882579208
##   loss_reduction = 2.59086177960244e-08
##   sample_size = 0.98803347914014
## 
## Computational engine: xgboost
final_xgb %>%
  fit(data = d_train) %>%
  pull_workflow_fit() %>%
  vip(geom = "point")
## Warning: `pull_workflow_fit()` was deprecated in workflows 0.2.3.
## Please use `extract_fit_parsnip()` instead.
## [15:37:03] WARNING: amalgamation/../src/learner.cc:1115: Starting in XGBoost 1.3.0, the default evaluation metric used with the objective 'binary:logistic' was changed from 'error' to 'logloss'. Explicitly set eval_metric if you'd like to restore the old behavior.

final_res <- last_fit(final_xgb, d_split)

collect_metrics(final_res)
final_res %>%
  collect_predictions() %>%
  roc_curve(truth = presence, .pred_0) %>%
  autoplot()

Review results

glm

glm_fit %>%
  extract_fit_parsnip() %>%
  tidy() %>%
  filter(p.value < 0.05)

• Blue tit density and land cover in 2000 significant predictors

glmnet

glmnet_fit %>%
  extract_fit_parsnip() 
## parsnip model object
## 
## Fit time:  63ms 
## $a0
##        s0        s1        s2        s3        s4        s5        s6        s7 
## -2.572646 -2.820915 -3.064575 -3.303484 -3.537358 -3.765813 -3.988407 -4.204674 
##        s8        s9       s10       s11       s12       s13       s14       s15 
## -4.414151 -4.616405 -4.811051 -4.997763 -5.175442 -5.303299 -5.408145 -5.510894 
##       s16       s17       s18       s19       s20       s21       s22       s23 
## -5.610139 -5.703714 -5.795258 -5.889259 -5.979184 -6.074934 -6.166247 -6.251581 
##       s24       s25       s26       s27       s28       s29       s30       s31 
## -6.331330 -6.405795 -6.475219 -6.539506 -6.598720 -6.653076 -6.703301 -6.802217 
##       s32       s33       s34       s35       s36       s37       s38       s39 
## -6.908797 -7.007100 -7.113132 -7.217797 -7.277613 -7.296324 -7.314345 -7.331853 
##       s40       s41       s42       s43       s44       s45       s46       s47 
## -7.348369 -7.364224 -7.339945 -7.010104 -6.685123 -6.389045 -6.119222 -5.869561 
##       s48       s49       s50       s51       s52       s53       s54       s55 
## -5.648676 -5.441223 -5.254611 -5.085001 -4.930600 -4.790036 -4.658298 -4.540853 
##       s56       s57       s58       s59       s60       s61       s62       s63 
## -4.434563 -4.338081 -4.250499 -4.167098 -4.093577 -4.027623 -3.964261 -3.908951 
##       s64       s65       s66 
## -3.859773 -3.811848 -3.770564 
## 
## $beta
## 10 x 67 sparse Matrix of class "dgCMatrix"
##    [[ suppressing 67 column names 's0', 's1', 's2' ... ]]
##                                                                          
## bt                     . 0.1089267 0.2138032 0.314877 0.4122959 0.5061359
## gsw                    . .         .         .        .         .        
## meantemp               . .         .         .        .         .        
## diurnal_range          . .         .         .        .         .        
## min_temp_coldest_month . .         .         .        .         .        
## lc1990                 . .         .         .        .         .        
## lc2000                 . .         .         .        .         .        
## lc2015                 . .         .         .        .         .        
## x                      . .         .         .        .         .        
## y                      . .         .         .        .         .        
##                                                                         
## bt                     0.5964235 0.6831537 0.7663051 0.8458513 0.9217698
## gsw                    .         .         .         .         .        
## meantemp               .         .         .         .         .        
## diurnal_range          .         .         .         .         .        
## min_temp_coldest_month .         .         .         .         .        
## lc1990                 .         .         .         .         .        
## lc2000                 .         .         .         .         .        
## lc2015                 .         .         .         .         .        
## x                      .         .         .         .         .        
## y                      .         .         .         .         .        
##                                                                     
## bt                     0.9940488 1.05151674  1.105254633  1.15927244
## gsw                    .         0.01112538  0.018948505  0.02210233
## meantemp               .         .           .            .         
## diurnal_range          .         .           .            .         
## min_temp_coldest_month .         .           .            .         
## lc1990                 .         .           .            .         
## lc2000                 .         .          -0.007446317 -0.01786469
## lc2015                 .         .           .            .         
## x                      .         .           .            .         
## y                      .         .           .            .         
##                                                                       
## bt                      1.21156181  1.26063355  1.30591236  1.34887580
## gsw                     0.02485489  0.02822342  0.03199309  0.03628378
## meantemp                .           .           .           .         
## diurnal_range           .           .           .           .         
## min_temp_coldest_month  .           .           .           .         
## lc1990                  .           .           .           .         
## lc2000                 -0.02774801 -0.03707173 -0.04580624 -0.05405815
## lc2015                  .           .           .           .         
## x                       .           .           .           .         
## y                       .           .           .           .         
##                                                                               
## bt                      1.386285e+00  1.421601e+00  1.456224e+00  1.487329e+00
## gsw                     3.935482e-02  4.234712e-02  4.734196e-02  5.379790e-02
## meantemp                .             .             .             .           
## diurnal_range           .             .             .             .           
## min_temp_coldest_month  .             .             .             .           
## lc1990                  .             .            -1.642412e-03 -3.420672e-03
## lc2000                 -6.142002e-02 -6.832315e-02 -7.235849e-02 -7.571371e-02
## lc2015                  .             .             .             .           
## x                       3.934227e-08  7.694969e-08  1.116772e-07  1.431861e-07
## y                       .             .             .             .           
##                                                                               
## bt                      1.515422e+00  1.541135e+00  1.564773e+00  1.586521e+00
## gsw                     6.069014e-02  6.757914e-02  7.430352e-02  8.079491e-02
## meantemp                .             .             .             .           
## diurnal_range           .             .             .             .           
## min_temp_coldest_month  .             .             .             .           
## lc1990                 -5.069183e-03 -6.593311e-03 -8.000694e-03 -9.298977e-03
## lc2000                 -7.881051e-02 -8.167838e-02 -8.433543e-02 -8.679570e-02
## lc2015                  .             .             .             .           
## x                       1.720177e-07  1.984002e-07  2.225375e-07  2.446237e-07
## y                       .             .             .             .           
##                                                                               
## bt                      1.606554e+00  1.625242e+00  1.641857e+00  1.656955e+00
## gsw                     8.702133e-02  9.359476e-02  1.001154e-01  1.063439e-01
## meantemp                .             .             .             .           
## diurnal_range           .             .             .             .           
## min_temp_coldest_month  .             .             .             .           
## lc1990                 -1.046556e-02 -1.098328e-02 -1.144120e-02 -1.186520e-02
## lc2000                 -8.905893e-02 -9.071263e-02 -9.224882e-02 -9.366238e-02
## lc2015                 -1.415562e-04 -2.001251e-03 -3.729451e-03 -5.309295e-03
## x                       2.647471e-07  2.820209e-07  2.981163e-07  3.128514e-07
## y                       .             .             .             .           
##                                                                               
## bt                      1.667107e+00  1.674874e+00  1.681619e+00  1.678396e+00
## gsw                     1.252937e-01  1.468891e-01  1.670778e-01  1.930135e-01
## meantemp                .             .             .             .           
## diurnal_range           .             .             .             .           
## min_temp_coldest_month  .             .             .             1.367366e-03
## lc1990                 -1.241712e-02 -1.303804e-02 -1.360878e-02 -1.413593e-02
## lc2000                 -9.453158e-02 -9.520020e-02 -9.582464e-02 -9.715198e-02
## lc2015                 -6.937649e-03 -8.353418e-03 -9.634085e-03 -1.068705e-02
## x                       3.416055e-07  3.730504e-07  4.027579e-07  4.465784e-07
## y                       6.254159e-08  1.385766e-07  2.083233e-07  3.136534e-07
##                                                                               
## bt                      1.671486e+00  1.665014e+00  1.658995e+00  1.653111e+00
## gsw                     2.201478e-01  2.474515e-01  2.748337e-01  3.003151e-01
## meantemp                .             .             .             .           
## diurnal_range           .            -6.538100e-04 -1.900201e-03 -3.029347e-03
## min_temp_coldest_month  3.201141e-03  4.735416e-03  5.985319e-03  7.135330e-03
## lc1990                 -1.462828e-02 -1.505695e-02 -1.542569e-02 -1.576633e-02
## lc2000                 -9.870713e-02 -1.001887e-01 -1.015975e-01 -1.029027e-01
## lc2015                 -1.158433e-02 -1.236920e-02 -1.305017e-02 -1.365749e-02
## x                       4.939074e-07  5.490421e-07  6.105436e-07  6.663775e-07
## y                       4.274352e-07  5.297671e-07  6.214288e-07  7.053349e-07
##                                                                               
## bt                      1.648312e+00  1.643317e+00  1.639298e+00  1.636597e+00
## gsw                     3.233000e-01  3.448584e-01  3.642364e-01  3.821765e-01
## meantemp                .             .             .            -5.869640e-04
## diurnal_range          -4.053641e-03 -4.982266e-03 -5.825490e-03 -6.493356e-03
## min_temp_coldest_month  8.184524e-03  9.151927e-03  1.003322e-02  1.120039e-02
## lc1990                 -1.608017e-02 -1.636936e-02 -1.663516e-02 -1.688057e-02
## lc2000                 -1.041291e-01 -1.052532e-01 -1.063059e-01 -1.072206e-01
## lc2015                 -1.419610e-02 -1.467939e-02 -1.510953e-02 -1.553834e-02
## x                       7.168956e-07  7.629533e-07  8.046415e-07  8.566219e-07
## y                       7.817139e-07  8.517339e-07  9.154371e-07  9.668083e-07
##                                                                               
## bt                      1.634025e+00  1.636682e+00  1.639453e+00  1.642017e+00
## gsw                     4.026537e-01  4.177591e-01  4.313874e-01  4.438764e-01
## meantemp               -5.758206e-03 -1.087362e-02 -1.553809e-02 -1.979062e-02
## diurnal_range          -6.165959e-03 -5.774738e-03 -5.419614e-03 -5.097346e-03
## min_temp_coldest_month  1.529201e-02  1.925389e-02  2.286530e-02  2.615909e-02
## lc1990                 -1.708962e-02 -1.727451e-02 -1.744348e-02 -1.759795e-02
## lc2000                 -1.077020e-01 -1.082665e-01 -1.088023e-01 -1.093027e-01
## lc2015                 -1.617229e-02 -1.673690e-02 -1.724848e-02 -1.771294e-02
## x                       1.021890e-06  1.181574e-06  1.326766e-06  1.458877e-06
## y                       9.628811e-07  9.525892e-07  9.429517e-07  9.340709e-07
##                                                                               
## bt                      1.644310e+00  1.646561e+00  1.648470e+00  1.650309e+00
## gsw                     4.553592e-01  4.658003e-01  4.754569e-01  4.842437e-01
## meantemp               -2.372526e-02 -2.721040e-02 -3.048175e-02 -3.342658e-02
## diurnal_range          -4.789941e-03 -4.537124e-03 -4.283233e-03 -4.062309e-03
## min_temp_coldest_month  2.920398e-02  3.190864e-02  3.444229e-02  3.672590e-02
## lc1990                 -1.773826e-02 -1.786810e-02 -1.798531e-02 -1.809301e-02
## lc2000                 -1.097686e-01 -1.102024e-01 -1.106034e-01 -1.109755e-01
## lc2015                 -1.813585e-02 -1.851821e-02 -1.886756e-02 -1.918438e-02
## x                       1.580702e-06  1.688771e-06  1.789759e-06  1.880658e-06
## y                       9.252864e-07  9.183008e-07  9.109015e-07  9.045028e-07
##                                                                               
## bt                      1.651996e+00  1.653545e+00  1.654969e+00  1.656174e+00
## gsw                     4.922870e-01  4.996444e-01  5.063707e-01  5.125817e-01
## meantemp               -3.610393e-02 -3.854188e-02 -4.076192e-02 -4.284137e-02
## diurnal_range          -3.863459e-03 -3.683473e-03 -3.520489e-03 -3.357838e-03
## min_temp_coldest_month  3.880328e-02  4.069563e-02  4.241944e-02  4.403105e-02
## lc1990                 -1.819151e-02 -1.828152e-02 -1.836376e-02 -1.843810e-02
## lc2000                 -1.113192e-01 -1.116363e-01 -1.119286e-01 -1.121975e-01
## lc2015                 -1.947242e-02 -1.973438e-02 -1.997271e-02 -2.019049e-02
## x                       1.963231e-06  2.038349e-06  2.106693e-06  2.170477e-06
## y                       8.987223e-07  8.934600e-07  8.886699e-07  8.837013e-07
##                                                                               
## bt                      1.657380e+00  1.658486e+00  1.659501e+00  1.660433e+00
## gsw                     5.181929e-01  5.233200e-01  5.280027e-01  5.322762e-01
## meantemp               -4.469695e-02 -4.637689e-02 -4.790230e-02 -4.928752e-02
## diurnal_range          -3.220313e-03 -3.098146e-03 -2.988446e-03 -2.889826e-03
## min_temp_coldest_month  4.547161e-02  4.677698e-02  4.796302e-02  4.904077e-02
## lc1990                 -1.850651e-02 -1.856911e-02 -1.862632e-02 -1.867859e-02
## lc2000                 -1.124455e-01 -1.126731e-01 -1.128818e-01 -1.130732e-01
## lc2015                 -2.038802e-02 -2.056770e-02 -2.073124e-02 -2.088012e-02
## x                       2.227461e-06  2.279054e-06  2.325892e-06  2.368419e-06
## y                       8.795694e-07  8.759235e-07  8.726609e-07  8.697423e-07
##                                                                               
## bt                      1.661167e+00  1.661952e+00  1.662678e+00  1.663221e+00
## gsw                     5.362575e-01  5.398122e-01  5.430499e-01  5.460921e-01
## meantemp               -5.060464e-02 -5.176780e-02 -5.281208e-02 -5.381286e-02
## diurnal_range          -2.786225e-03 -2.701169e-03 -2.627478e-03 -2.548508e-03
## min_temp_coldest_month  5.006216e-02  5.096659e-02  5.178014e-02  5.255636e-02
## lc1990                 -1.872565e-02 -1.876898e-02 -1.880873e-02 -1.884446e-02
## lc2000                 -1.132484e-01 -1.134097e-01 -1.135570e-01 -1.136916e-01
## lc2015                 -2.101631e-02 -2.113998e-02 -2.125237e-02 -2.135520e-02
## x                       2.408664e-06  2.444289e-06  2.476317e-06  2.506846e-06
## y                       8.664966e-07  8.639274e-07  8.617671e-07  8.592635e-07
##                                                                               
## bt                      1.663822e+00  1.664379e+00  1.664778e+00  1.665226e+00
## gsw                     5.487864e-01  5.512324e-01  5.535578e-01  5.555942e-01
## meantemp               -5.468902e-02 -5.546924e-02 -5.622622e-02 -5.688184e-02
## diurnal_range          -2.484707e-03 -2.430575e-03 -2.371278e-03 -2.323448e-03
## min_temp_coldest_month  5.323886e-02  5.384864e-02  5.443603e-02  5.494880e-02
## lc1990                 -1.887743e-02 -1.890779e-02 -1.893495e-02 -1.896015e-02
## lc2000                 -1.138152e-01 -1.139280e-01 -1.140308e-01 -1.141253e-01
## lc2015                 -2.144853e-02 -2.153310e-02 -2.161073e-02 -2.168077e-02
## x                       2.533667e-06  2.557611e-06  2.580686e-06  2.600775e-06
## y                       8.573790e-07  8.558787e-07  8.539881e-07  8.526785e-07
## 
## $df
##  [1]  0  1  1  1  1  1  1  1  1  1  1  1  2  3  3  3  3  3  3  4  4  5  5  5  5
## [26]  5  5  6  6  6  6  7  7  7  8  8  9  9  9  9  9  9 10 10 10 10 10 10 10 10
## [51] 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
## 
## $dim
## [1] 10 67
## 
## $lambda
##  [1] 0.0557707238 0.0508162064 0.0463018347 0.0421885073 0.0384405966
##  [6] 0.0350256400 0.0319140586 0.0290789016 0.0264956122 0.0241418150
## [11] 0.0219971227 0.0200429589 0.0182623977 0.0166400166 0.0151617634
## [16] 0.0138148341 0.0125875624 0.0114693180 0.0104504154 0.0095220293
## [21] 0.0086761185 0.0079053560 0.0072030660 0.0065631655 0.0059801119
## [26] 0.0054488553 0.0049647940 0.0045237354 0.0041218592 0.0037556846
## [31] 0.0034220399 0.0031180353 0.0028410377 0.0025886477 0.0023586794
## [36] 0.0021491408 0.0019582171 0.0017842544 0.0016257462 0.0014813194
## [41] 0.0013497231 0.0012298174 0.0011205638 0.0010210160 0.0009303117
## [46] 0.0008476654 0.0007723612 0.0007037467 0.0006412278 0.0005842629
## [51] 0.0005323586 0.0004850653 0.0004419735 0.0004027097 0.0003669341
## [56] 0.0003343367 0.0003046352 0.0002775722 0.0002529135 0.0002304453
## [61] 0.0002099732 0.0001913198 0.0001743234 0.0001588370 0.0001447264
## [66] 0.0001318693 0.0001201544
## 
## $dev.ratio
##  [1] 3.512655e-14 1.606975e-02 3.016732e-02 4.254671e-02 5.341850e-02
##  [6] 6.296062e-02 7.132600e-02 7.864803e-02 8.504441e-02 9.061998e-02
## [11] 9.546868e-02 9.967494e-02 1.034056e-01 1.075584e-01 1.115405e-01
## [16] 1.150142e-01 1.180233e-01 1.205939e-01 1.228391e-01 1.248027e-01
## [21] 1.264928e-01 1.281047e-01 1.294983e-01 1.306789e-01 1.316785e-01
## [26] 1.325243e-01 1.332391e-01 1.338454e-01 1.343724e-01 1.348138e-01
## [31] 1.351844e-01 1.358187e-01 1.364410e-01 1.369626e-01 1.376821e-01
## [36] 1.383996e-01 1.390362e-01 1.396010e-01 1.400723e-01 1.404648e-01
## [41] 1.407924e-01 1.410650e-01 1.413446e-01 1.419726e-01 1.425247e-01
## [46] 1.429840e-01 1.433661e-01 1.436872e-01 1.439490e-01 1.441715e-01
## [51] 1.443548e-01 1.445071e-01 1.446338e-01 1.447392e-01 1.448286e-01
## [56] 1.449019e-01 1.449626e-01 1.450131e-01 1.450550e-01 1.450910e-01
## [61] 1.451204e-01 1.451446e-01 1.451655e-01 1.451824e-01 1.451963e-01
## [66] 1.452085e-01 1.452183e-01
## 
## $nulldev
## [1] 1653.323
## 
## $npasses
## [1] 903
## 
## $jerr
## [1] 0
## 
## $offset
## [1] FALSE
## 
## $classnames
## [1] "0" "1"
## 
## $call
## glmnet::glmnet(x = maybe_matrix(x), y = y, family = "binomial")
## 
## $nobs
## [1] 3229
## 
## attr(,"class")
## [1] "lognet" "glmnet"

random forest (ranger)

rf_fit %>%
  extract_fit_parsnip() %>%
  vip()

xgboost

final_xgb %>%
  fit(data = d_train) %>%
  pull_workflow_fit() %>%
  vip(geom = "point")
## Warning: `pull_workflow_fit()` was deprecated in workflows 0.2.3.
## Please use `extract_fit_parsnip()` instead.
## [15:37:34] WARNING: amalgamation/../src/learner.cc:1115: Starting in XGBoost 1.3.0, the default evaluation metric used with the objective 'binary:logistic' was changed from 'error' to 'logloss'. Explicitly set eval_metric if you'd like to restore the old behavior.