@@ -51,12 +51,30 @@ test_that("quantile_rand_forest handles allows setting the trees and mtry", {
5151 expect_identical(pars $ `_num_trees` , manual $ `_num_trees` )
5252})
5353
54- test_that(" quantile_rand_forest predicts reasonable quantiles " , {
54+ test_that(" quantile_rand_forest operates with arx_forecaster " , {
5555 spec <- rand_forest(mode = " regression" ) %> %
56- set_engine(" grf_quantiles" , quantiles = c(.2 , .5 , .8 ))
57- expect_silent(out <- fit(spec , formula = y ~ x + z , data = tib ))
58- # swapping around the probabilities, because somehow this happens in practice,
59- # but I'm not sure how to reproduce
60- out $ fit $ quantiles.orig <- c(0.5 , 0.9 , 0.1 )
61- expect_no_error(predict(out , tib ))
56+ set_engine(" grf_quantiles" , quantiles = c(.1 , .2 , .5 , .8 , .9 )) # non-default
57+ expect_identical(rlang :: eval_tidy(spec $ eng_args $ quantiles ), c(.1 , .2 , .5 , .8 , .9 ))
58+ tib <- as_epi_df(tibble(time_value = 1 : 25 , geo_value = " ca" , value = rnorm(25 )))
59+ o <- arx_fcast_epi_workflow(tib , " value" , trainer = spec )
60+ spec2 <- parsnip :: extract_spec_parsnip(o )
61+ expect_identical(
62+ rlang :: eval_tidy(spec2 $ eng_args $ quantiles ),
63+ rlang :: eval_tidy(spec $ eng_args $ quantiles )
64+ )
65+ spec <- rand_forest(mode = " regression" , " grf_quantiles" )
66+ expect_null(rlang :: eval_tidy(spec $ eng_args ))
67+ o <- arx_fcast_epi_workflow(tib , " value" , trainer = spec )
68+ spec2 <- parsnip :: extract_spec_parsnip(o )
69+ expect_identical(
70+ rlang :: eval_tidy(spec2 $ eng_args $ quantiles ),
71+ c(.05 , .1 , .5 , .9 , .95 ) # merged with arx_args default
72+ )
73+ df <- epidatasets :: counts_subset %> % filter(time_value > = " 2021-10-01" )
74+
75+ z <- arx_forecaster(df , " cases" , " cases" , spec2 )
76+ expect_identical(
77+ nested_quantiles(z $ predictions $ .pred_distn [1 ])[[1 ]]$ quantile_levels ,
78+ c(.05 , .1 , .5 , .9 , .95 )
79+ )
6280})
0 commit comments