@@ -38,14 +38,17 @@ expect_true(nrow(mfx) > 0)
3838
3939
4040# conformal
41+ set.seed(48103 )
4142dat <- get_dataset(" penguins" , " palmerpenguins" ) | > na.omit()
43+ dat <- dat [sample(1 : nrow(dat ), nrow(dat )), ] # shuffle species
4244mod <- set_engine(linear_reg(), " lm" ) | >
4345 fit(body_mass_g ~ bill_length_mm + flipper_length_mm + species ,
4446 data = na.omit(dat ))
4547p <- predictions(mod , newdata = dat [1 : 100 , ]) | >
4648 inferences(
4749 R = 3 ,
4850 method = " conformal_cv+" ,
51+ data_train = dat [1 : 100 , ],
4952 data_calib = dat [101 : nrow(dat ), ]
5053 )
5154expect_inherits(p , " predictions" )
@@ -65,6 +68,7 @@ expect_true("std.error" %in% colnames(p))
6568p <- predictions(mod , newdata = bikes [1 : 200 , ], vcov = FALSE ) | >
6669 inferences(
6770 method = " conformal_split" ,
71+ data_train = bikes [1 : 200 , ],
6872 data_calib = bikes [201 : nrow(bikes ), ])
6973expect_inherits(p , " predictions" )
7074
@@ -123,3 +127,39 @@ lr_fit <- lr_wf |>
123127mfx <- slopes(lr_fit , newdata = my_data , variable = " x" )
124128expect_equivalent(mfx $ x , my_data $ x )
125129expect_equivalent(mfx $ y , my_data $ y )
130+
131+
132+ # Bootstrap
133+ set.seed(48103 )
134+ nobs <- 50
135+ wf <- workflow() | >
136+ add_model(boost_tree(mode = " regression" )) | >
137+ add_recipe(
138+ recipe(Sepal.Length ~ . , data = iris ) | >
139+ # 1. Convert character predictors to factors (if any)
140+ step_string2factor(all_nominal_predictors()) | >
141+ # 2. Dummy-code all nominal predictors
142+ step_dummy(all_nominal_predictors())
143+ ) | >
144+ fit(iris )
145+ mfx1 <- comparisons(wf , newdata = iris , variable = " Sepal.Width" , vcov = FALSE )
146+ mfx2 <- inferences(mfx1 , R = 100 , method = " rsample" , data_train = iris ) | >
147+ suppressWarnings()
148+ expect_false(" conf.low" %in% colnames(mfx1 ))
149+ expect_true(" conf.low" %in% colnames(mfx2 ))
150+
151+
152+ # Bootstrap for some supported models but not all
153+ z <- boost_tree(" regression" ) | >
154+ fit(hp ~ . , data = mtcars )
155+ comparisons(z , variables = " mpg" , newdata = mtcars , vcov = FALSE ) | >
156+ inferences(R = 10 , method = " boot" , data_train = mtcars ) | >
157+ suppressWarnings() | >
158+ expect_error(pattern = " Failed to refit" )
159+ z <- linear_reg() | >
160+ fit(hp ~ . , data = mtcars )
161+ cmp <- comparisons(z , variables = " mpg" , newdata = mtcars , vcov = FALSE ) | >
162+ inferences(R = 10 , method = " boot" , data_train = mtcars ) | >
163+ suppressWarnings()
164+ expect_inherits(cmp , " comparisons" )
165+ expect_true(" conf.low" %in% colnames(cmp ))
0 commit comments