library(magrittr)
library(bikeHelpR)
library(dbplyr)
library(xgboost)
library(yardstick)
## For binary classification, the first factor level is assumed to be the event.
## Set the global option `yardstick.event_first` to `FALSE` to change this.
con <<- DBI::dbConnect(odbc::odbc(), "Content DB")
pins::board_register_rsconnect(server = "https://colorado.rstudio.com/rsc",
                               key = Sys.getenv("RSTUDIOCONNECT_API_KEY"))

Load Models and Test Data

mods <- list(r_xgb = pins::pin_get("bike_model_rxgb", board = "rsconnect"))
mod_params <<- pins::pin_get("bike_model_params", board = "rsconnect")
test <- bike_test_dat(con, mod_params$split_date) %>%
  recipes::bake(mod_params$recipe, .) 
## Using 2020-02-05 and 2020-02-06 as test data.

Goodness of Fit

Write predictions to database and goodness of fit metrics to pin

purrr::imap_dfr(mods, bike_mod_results, test, prep_r_xgb_mat)
## [1] "Saving test data to db."
## [1] "Writing Goodness of Fit Pin."
## # A tibble: 31 x 6
##    train_date mod    rmse   mae   ccc    r2
##    <date>     <chr> <dbl> <dbl> <dbl> <dbl>
##  1 2020-02-06 r_xgb  3.50  2.64 0.768 0.640
##  2 2020-02-05 r_xgb  3.67  2.70 0.741 0.595
##  3 2020-02-04 r_xgb  3.65  2.66 0.745 0.611
##  4 2020-02-03 r_xgb  3.66  2.65 0.720 0.550
##  5 2020-02-02 r_xgb  4.01  3.02 0.681 0.468
##  6 2020-02-01 r_xgb  3.65  2.84 0.740 0.584
##  7 2020-01-31 r_xgb  3.60  2.81 0.742 0.585
##  8 2020-01-30 r_xgb  3.81  2.89 0.715 0.537
##  9 2020-01-29 r_xgb  3.82  2.88 0.712 0.527
## 10 2020-01-28 r_xgb  3.83  2.90 0.713 0.529
## # … with 21 more rows