Goal: be able to predict the ceo departure

Import Data

library(tidyverse)
## Warning: package 'purrr' was built under R version 4.3.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.1
## ✔ purrr     1.0.4     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(textrecipes)
## Warning: package 'textrecipes' was built under R version 4.3.3
## Loading required package: recipes
## Warning: package 'recipes' was built under R version 4.3.3
## 
## Attaching package: 'recipes'
## 
## The following object is masked from 'package:stringr':
## 
##     fixed
## 
## The following object is masked from 'package:stats':
## 
##     step
library(correlationfunnel)
## ══ correlationfunnel Tip #1 ════════════════════════════════════════════════════
## Make sure your data is not overly imbalanced prior to using `correlate()`.
## If less than 5% imbalance, consider sampling. :)
data <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2021/2021-04-27/departures.csv')
## Rows: 9423 Columns: 19
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr   (8): coname, exec_fullname, interim_coceo, still_there, notes, sources...
## dbl  (10): dismissal_dataset_id, gvkey, fyear, co_per_rol, departure_code, c...
## dttm  (1): leftofc
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Clean Data

skimr::skim(data)
Data summary
Name data
Number of rows 9423
Number of columns 19
_______________________
Column type frequency:
character 8
numeric 10
POSIXct 1
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
coname 0 1.00 2 30 0 3860 0
exec_fullname 0 1.00 5 790 0 8701 0
interim_coceo 9105 0.03 6 7 0 6 0
still_there 7311 0.22 3 10 0 77 0
notes 1644 0.83 5 3117 0 7755 0
sources 1475 0.84 18 1843 0 7915 0
eight_ks 4499 0.52 69 3884 0 4914 0
_merge 0 1.00 11 11 0 1 0

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
dismissal_dataset_id 0 1.00 5684.10 25005.46 1 2305.5 4593 6812.5 559044 ▇▁▁▁▁
gvkey 0 1.00 40132.48 53921.34 1004 7337.0 14385 60900.5 328795 ▇▁▁▁▁
fyear 0 1.00 2007.74 8.19 1987 2000.0 2008 2016.0 2020 ▁▆▅▅▇
co_per_rol 0 1.00 25580.22 18202.38 -1 8555.5 22980 39275.5 64602 ▇▆▅▃▃
departure_code 1667 0.82 5.20 1.53 1 5.0 5 7.0 9 ▁▃▇▅▁
ceo_dismissal 1813 0.81 0.20 0.40 0 0.0 0 0.0 1 ▇▁▁▁▂
tenure_no_ceodb 0 1.00 1.03 0.17 0 1.0 1 1.0 3 ▁▇▁▁▁
max_tenure_ceodb 0 1.00 1.05 0.24 1 1.0 1 1.0 4 ▇▁▁▁▁
fyear_gone 1802 0.81 2006.64 13.63 1980 2000.0 2007 2013.0 2997 ▇▁▁▁▁
cik 245 0.97 741469.17 486551.43 1750 106413.0 857323 1050375.8 1808065 ▆▁▇▂▁

Variable type: POSIXct

skim_variable n_missing complete_rate min max median n_unique
leftofc 1802 0.81 1981-01-01 2998-04-27 2006-12-31 3627
data_clean <- data %>%
    select(-c(`_merge`,, still_there, sources, eight_ks)) %>%
    na.omit() %>%
    mutate(across(c(departure_code, ceo_dismissal), as.factor))

Explore Data

data_clean %>% count(ceo_dismissal)
## # A tibble: 2 × 2
##   ceo_dismissal     n
##   <fct>         <int>
## 1 0               253
## 2 1                16
data_clean %>%
    ggplot(aes(fyear)) +
    geom_bar()

correlation plot

data_binarized <- data_clean %>%
    select(-leftofc, -notes) %>%
    binarize()
data_binarized %>% glimpse()
## Rows: 269
## Columns: 48
## $ `dismissal_dataset_id__-Inf_2214` <dbl> 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, …
## $ dismissal_dataset_id__2214_4496   <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, …
## $ dismissal_dataset_id__4496_6636   <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ dismissal_dataset_id__6636_Inf    <dbl> 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ coname__BOB_EVANS_FARMS           <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ coname__NORDSTROM_INC             <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ `coname__-OTHER`                  <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
## $ `gvkey__-Inf_6802`                <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, …
## $ gvkey__6802_13700                 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, …
## $ gvkey__13700_29791                <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ gvkey__29791_Inf                  <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ `fyear__-Inf_2001`                <dbl> 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, …
## $ fyear__2001_2007                  <dbl> 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, …
## $ fyear__2007_2014                  <dbl> 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ fyear__2014_Inf                   <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ `co_per_rol__-Inf_12685`          <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
## $ co_per_rol__12685_25457           <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ co_per_rol__25457_43559           <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ co_per_rol__43559_Inf             <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ exec_fullname__George_J._Harad    <dbl> 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ `exec_fullname__-OTHER`           <dbl> 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, …
## $ departure_code__1                 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ departure_code__3                 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, …
## $ departure_code__5                 <dbl> 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, …
## $ departure_code__6                 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ departure_code__7                 <dbl> 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, …
## $ `departure_code__-OTHER`          <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ ceo_dismissal__0                  <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, …
## $ ceo_dismissal__1                  <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, …
## $ `interim_coceo__co-CEO`           <dbl> 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, …
## $ `interim_coceo__Co-CEO`           <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ `interim_coceo__CO-CEO`           <dbl> 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, …
## $ interim_coceo__Interim            <dbl> 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, …
## $ `interim_coceo__-OTHER`           <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tenure_no_ceodb__1                <dbl> 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, …
## $ tenure_no_ceodb__2                <dbl> 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, …
## $ tenure_no_ceodb__3                <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ max_tenure_ceodb__1               <dbl> 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, …
## $ max_tenure_ceodb__2               <dbl> 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, …
## $ max_tenure_ceodb__3               <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ `fyear_gone__-Inf_2001`           <dbl> 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, …
## $ fyear_gone__2001_2008             <dbl> 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, …
## $ fyear_gone__2008_2014             <dbl> 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ fyear_gone__2014_Inf              <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ `cik__-Inf_96287`                 <dbl> 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, …
## $ cik__96287_833829                 <dbl> 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, …
## $ cik__833829_1042893               <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, …
## $ cik__1042893_Inf                  <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
data_correlation <- data_binarized %>%
    correlate(ceo_dismissal__1 )


data_correlation
## # A tibble: 48 × 3
##    feature        bin       correlation
##    <fct>          <chr>           <dbl>
##  1 ceo_dismissal  0              -1    
##  2 ceo_dismissal  1               1    
##  3 departure_code 3               0.966
##  4 departure_code 7              -0.352
##  5 coname         -OTHER         -0.175
##  6 interim_coceo  CO-CEO          0.145
##  7 co_per_rol     43559_Inf      -0.145
##  8 departure_code 5              -0.142
##  9 interim_coceo  Interim        -0.140
## 10 fyear          -Inf_2001       0.129
## # ℹ 38 more rows
data_correlation %>%
    correlationfunnel::plot_correlation_funnel()

split data

library(tidymodels)
## Warning: package 'tidymodels' was built under R version 4.3.3
## ── Attaching packages ────────────────────────────────────── tidymodels 1.3.0 ──
## ✔ broom        1.0.7     ✔ rsample      1.2.1
## ✔ dials        1.4.0     ✔ tune         1.3.0
## ✔ infer        1.0.7     ✔ workflows    1.2.0
## ✔ modeldata    1.4.0     ✔ workflowsets 1.1.0
## ✔ parsnip      1.3.0     ✔ yardstick    1.3.2
## Warning: package 'broom' was built under R version 4.3.3
## Warning: package 'dials' was built under R version 4.3.3
## Warning: package 'scales' was built under R version 4.3.3
## Warning: package 'modeldata' was built under R version 4.3.3
## Warning: package 'parsnip' was built under R version 4.3.3
## Warning: package 'tune' was built under R version 4.3.3
## Warning: package 'workflows' was built under R version 4.3.3
## Warning: package 'yardstick' was built under R version 4.3.3
## ── Conflicts ───────────────────────────────────────── tidymodels_conflicts() ──
## ✖ scales::discard() masks purrr::discard()
## ✖ dplyr::filter()   masks stats::filter()
## ✖ recipes::fixed()  masks stringr::fixed()
## ✖ dplyr::lag()      masks stats::lag()
## ✖ yardstick::spec() masks readr::spec()
## ✖ recipes::step()   masks stats::step()
set.seed(1234)
data_clean <- data_clean %>% sample_n(100)

data_split <- initial_split(data_clean, strata = ceo_dismissal )
data_train <- training(data_split)
data_test <- testing(data_split)

data_cv <- rsample::vfold_cv(data_train, strata = ceo_dismissal)
data_cv
## #  10-fold cross-validation using stratification 
## # A tibble: 10 × 2
##    splits         id    
##    <list>         <chr> 
##  1 <split [67/8]> Fold01
##  2 <split [67/8]> Fold02
##  3 <split [67/8]> Fold03
##  4 <split [67/8]> Fold04
##  5 <split [67/8]> Fold05
##  6 <split [68/7]> Fold06
##  7 <split [68/7]> Fold07
##  8 <split [68/7]> Fold08
##  9 <split [68/7]> Fold09
## 10 <split [68/7]> Fold10

##prepocess data

library(themis)
## Warning: package 'themis' was built under R version 4.3.3
xgboost_rec <- recipes::recipe(ceo_dismissal ~ ., data = data_train) %>%
    update_role(dismissal_dataset_id, new_role = "ID")  %>%
    step_tokenize(notes) %>%
    step_tokenfilter(notes, max_tokens = 50) %>%
    step_tf(notes)  %>%
    step_date(leftofc, keep_original_cols = FALSE) %>%
    step_other(coname, exec_fullname) %>%
    step_dummy(all_nominal_predictors()) %>%
    step_log(gvkey, tenure_no_ceodb, max_tenure_ceodb) %>%
    step_smote(ceo_dismissal)

xgboost_rec %>% prep() %>% juice() %>% glimpse()
## Rows: 138
## Columns: 89
## $ dismissal_dataset_id  <dbl> 4496, 7420, 7503, 423, 5782, 6041, 931, 1404, 58…
## $ gvkey                 <dbl> 9.545097, 11.082881, 11.092413, 7.667626, 10.130…
## $ fyear                 <dbl> 2002, 2002, 2010, 2005, 2012, 2014, 2008, 2018, …
## $ co_per_rol            <dbl> 20578, 25315, 17477, 19697, 45955, 16402, 13505,…
## $ tenure_no_ceodb       <dbl> 0.0000000, 0.0000000, 0.6931472, 0.0000000, 0.00…
## $ max_tenure_ceodb      <dbl> 0.0000000, 0.0000000, 0.6931472, 0.0000000, 0.69…
## $ fyear_gone            <dbl> 2003, 2003, 2011, 2005, 2012, 2010, 2008, 2019, …
## $ cik                   <dbl> 819706, 1038339, 1042893, 945489, 883943, 891103…
## $ ceo_dismissal         <fct> 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ tf_notes_a            <dbl> 3, 1, 0, 2, 1, 1, 3, 1, 2, 1, 2, 0, 1, 2, 0, 1, …
## $ tf_notes_after        <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, …
## $ tf_notes_also         <dbl> 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, …
## $ tf_notes_and          <dbl> 2, 2, 0, 2, 2, 2, 1, 1, 2, 1, 4, 2, 3, 1, 1, 2, …
## $ tf_notes_announced    <dbl> 2, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, …
## $ tf_notes_as           <dbl> 0, 0, 0, 1, 1, 3, 3, 3, 1, 1, 4, 2, 6, 1, 0, 2, …
## $ tf_notes_be           <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, …
## $ tf_notes_been         <dbl> 2, 1, 0, 0, 0, 0, 0, 0, 2, 0, 2, 1, 0, 0, 1, 0, …
## $ tf_notes_board        <dbl> 2, 1, 0, 1, 1, 0, 0, 3, 0, 0, 3, 2, 3, 1, 3, 1, …
## $ tf_notes_by           <dbl> 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 2, 0, 0, …
## $ tf_notes_ceo          <dbl> 1, 0, 0, 0, 2, 0, 1, 1, 0, 2, 4, 1, 0, 2, 0, 1, …
## $ tf_notes_chairman     <dbl> 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 2, …
## $ tf_notes_chief        <dbl> 1, 1, 0, 2, 0, 1, 2, 3, 1, 1, 1, 2, 3, 0, 1, 1, …
## $ tf_notes_co           <dbl> 1, 0, 0, 0, 0, 0, 0, 0, 3, 0, 1, 0, 0, 0, 0, 1, …
## $ tf_notes_company      <dbl> 0, 0, 0, 1, 0, 4, 0, 1, 0, 1, 2, 1, 1, 1, 0, 0, …
## $ tf_notes_directors    <dbl> 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 1, 1, 1, 0, 1, 1, …
## $ tf_notes_effective    <dbl> 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 2, 0, 1, 0, …
## $ tf_notes_executive    <dbl> 1, 1, 0, 2, 0, 2, 1, 2, 1, 2, 0, 2, 3, 0, 2, 1, …
## $ tf_notes_for          <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, …
## $ tf_notes_from         <dbl> 1, 2, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, …
## $ tf_notes_has          <dbl> 2, 1, 0, 1, 1, 0, 0, 1, 2, 0, 3, 2, 0, 0, 2, 0, …
## $ tf_notes_he           <dbl> 1, 0, 2, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, …
## $ tf_notes_his          <dbl> 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, …
## $ tf_notes_in           <dbl> 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 2, 0, 1, …
## $ tf_notes_inc          <dbl> 2, 0, 0, 1, 0, 0, 1, 0, 3, 0, 0, 1, 1, 1, 1, 0, …
## $ tf_notes_interim      <dbl> 1, 2, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 2, …
## $ tf_notes_is           <dbl> 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 2, 0, 1, …
## $ tf_notes_it           <dbl> 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, …
## $ tf_notes_its          <dbl> 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 3, 1, 0, 1, 1, 0, …
## $ tf_notes_march        <dbl> 2, 0, 0, 0, 1, 0, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0, …
## $ tf_notes_member       <dbl> 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, …
## $ tf_notes_mr           <dbl> 0, 1, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 2, …
## $ tf_notes_named        <dbl> 1, 0, 0, 1, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 0, 0, …
## $ tf_notes_new          <dbl> 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, …
## $ tf_notes_of           <dbl> 2, 4, 0, 2, 1, 3, 3, 6, 3, 0, 4, 2, 6, 1, 2, 3, …
## $ tf_notes_officer      <dbl> 1, 1, 0, 2, 0, 0, 1, 3, 1, 0, 0, 2, 3, 0, 1, 1, …
## $ tf_notes_on           <dbl> 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 2, 0, 1, 2, 0, 0, …
## $ tf_notes_president    <dbl> 1, 1, 0, 2, 1, 0, 0, 0, 1, 0, 1, 2, 3, 0, 1, 2, …
## $ tf_notes_served       <dbl> 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, …
## $ tf_notes_since        <dbl> 1, 1, 0, 0, 0, 0, 1, 0, 2, 0, 2, 1, 0, 0, 1, 0, …
## $ tf_notes_that         <dbl> 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, …
## $ tf_notes_the          <dbl> 0, 1, 0, 2, 1, 7, 2, 6, 0, 2, 11, 1, 7, 3, 3, 2,…
## $ tf_notes_to           <dbl> 0, 0, 1, 0, 0, 0, 1, 0, 2, 1, 4, 1, 2, 2, 2, 0, …
## $ tf_notes_until        <dbl> 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, …
## $ tf_notes_vice         <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, …
## $ tf_notes_was          <dbl> 1, 2, 0, 1, 0, 6, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, …
## $ tf_notes_who          <dbl> 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, …
## $ tf_notes_will         <dbl> 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 2, 2, 1, 1, …
## $ tf_notes_with         <dbl> 3, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, …
## $ tf_notes_year         <dbl> 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ leftofc_year          <dbl> 2003, 2003, 2011, 2005, 2012, 2010, 2008, 2019, …
## $ coname_other          <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
## $ exec_fullname_other   <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
## $ departure_code_X2     <dbl> 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ departure_code_X3     <dbl> 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ departure_code_X4     <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ departure_code_X5     <dbl> 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, …
## $ departure_code_X6     <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ departure_code_X7     <dbl> 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, …
## $ interim_coceo_Co.CEO  <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, …
## $ interim_coceo_CO.CEO  <dbl> 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ interim_coceo_interim <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ interim_coceo_Interim <dbl> 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, …
## $ leftofc_dow_Mon       <dbl> 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, …
## $ leftofc_dow_Tue       <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, …
## $ leftofc_dow_Wed       <dbl> 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, …
## $ leftofc_dow_Thu       <dbl> 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, …
## $ leftofc_dow_Fri       <dbl> 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, …
## $ leftofc_dow_Sat       <dbl> 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, …
## $ leftofc_month_Feb     <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ leftofc_month_Mar     <dbl> 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, …
## $ leftofc_month_Apr     <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, …
## $ leftofc_month_May     <dbl> 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ leftofc_month_Jun     <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ leftofc_month_Jul     <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ leftofc_month_Aug     <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ leftofc_month_Sep     <dbl> 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, …
## $ leftofc_month_Oct     <dbl> 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, …
## $ leftofc_month_Nov     <dbl> 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, …
## $ leftofc_month_Dec     <dbl> 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …

specify model

xgboost_spec <- 
  boost_tree(trees = tune()) %>% 
  set_mode("classification") %>% 
  set_engine("xgboost") 

xgboost_workflow <- 
  workflow() %>% 
  add_recipe(xgboost_rec) %>% 
  add_model(xgboost_spec) 

tune hyperparameters

doParallel::registerDoParallel()

set.seed(65743)
xgboost_tune <- 
    tune_grid(xgboost_workflow,
              resamples = data_cv,
              grid = 5)
## Warning: ! tune detected a parallel backend registered with foreach but no backend
##   registered with future.
## ℹ Support for parallel processing with foreach was soft-deprecated in tune
##   1.2.1.
## ℹ See ?parallelism (`?tune::parallelism()`) to learn more.
## Warning: package 'xgboost' was built under R version 4.3.3