suppressPackageStartupMessages(library(tidyverse))
library(targets)
library(DT)
knitr::opts_knit$set(root.dir = "../../")
tar_read(p_tscv)
Test set predictions (blue bars) of each iteration.
df_cv_preds_and_coefs <- tar_read(df_cv_preds_and_coefs)
df_cv_preds_and_coefs
## # A tibble: 45 × 6
## year_start_act category_id index_past index_next_year formula_str pred
## <dbl> <chr> <list> <list> <chr> <lis>
## 1 2011 cnsn <int [128]> <int [130]> has_finding ~ n… <tib…
## 2 2012 cnsn <int [258]> <int [105]> has_finding ~ n… <tib…
## 3 2013 cnsn <int [363]> <int [85]> has_finding ~ n… <tib…
## 4 2014 cnsn <int [448]> <int [98]> has_finding ~ n… <tib…
## 5 2015 cnsn <int [546]> <int [94]> has_finding ~ n… <tib…
## 6 2016 cnsn <int [640]> <int [83]> has_finding ~ n… <tib…
## 7 2017 cnsn <int [723]> <int [46]> has_finding ~ n… <tib…
## 8 2018 cnsn <int [769]> <int [39]> has_finding ~ n… <tib…
## 9 2019 cnsn <int [808]> <int [3]> has_finding ~ n… <tib…
## 10 2015 dtin <int [546]> <int [94]> has_finding ~ n… <tib…
## # … with 35 more rows
pred <- df_cv_preds_and_coefs$pred[[1]]
pred
## # A tibble: 1 × 3
## pred_train pred_valid coefs
## <list> <list> <list>
## 1 <tibble [128 × 3]> <tibble [130 × 3]> <tibble [10 × 8]>
df_cv_preds_and_coefs %>%
select(year_start_act, category_id, pred) %>%
mutate(pred_valid = map(pred, "pred_valid")) %>%
select(- pred) %>%
unnest(pred_valid) %>%
unnest(pred_valid)
## # A tibble: 3,089 × 5
## year_start_act category_id activity_id_new pred_yes obs
## <dbl> <chr> <chr> <dbl> <dbl>
## 1 2011 cnsn 00203 0.418 0
## 2 2011 cnsn 00318 0.277 0
## 3 2011 cnsn 00319 0.558 0
## 4 2011 cnsn 00329 0.304 1
## 5 2011 cnsn 00348 0.471 0
## 6 2011 cnsn 00355 0.471 0
## 7 2011 cnsn 00362 0.471 0
## 8 2011 cnsn 00368 0.320 1
## 9 2011 cnsn 00369 0.550 0
## 10 2011 cnsn 00370 0.320 1
## # … with 3,079 more rows
Coefficients and coefficient statistics of each iteration.
df_cv_preds_and_coefs %>%
select(year_start_act, category_id, pred) %>%
mutate(coefs = map(pred, "coefs")) %>%
select(- pred) %>%
unnest(coefs) %>%
unnest(coefs) %>%
DT::datatable()