Skip to content

Commit 3e46c0d

Browse files
committed
adjust tolerance for better testing
1 parent d645c0a commit 3e46c0d

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

tests/testthat/test_logistic_reg_stan.R

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ library(tibble)
66
# ------------------------------------------------------------------------------
77

88
context("execution tests for stan logistic regression")
9-
source("helper-objects.R")
9+
source(test_path("helper-objects.R"))
10+
1011

1112
lending_club <- head(lending_club, 200)
1213
lc_form <- as.formula(Class ~ log(funded_amnt) + int_rate)
@@ -106,7 +107,8 @@ test_that('stan_glm probability', {
106107

107108
expect_equivalent(
108109
xy_pred %>% as.data.frame(),
109-
parsnip:::predict_classprob.model_fit(xy_fit, lending_club[1:7, num_pred]) %>% as.data.frame()
110+
parsnip:::predict_classprob.model_fit(xy_fit, lending_club[1:7, num_pred]) %>% as.data.frame(),
111+
tolerance = 0.1
110112
)
111113

112114
res_form <- fit(
@@ -131,7 +133,8 @@ test_that('stan_glm probability', {
131133
expect_equivalent(
132134
form_pred %>% as.data.frame(),
133135
parsnip:::predict_classprob.model_fit(res_form, lending_club[1:7, c("funded_amnt", "int_rate")]) %>%
134-
as.data.frame()
136+
as.data.frame(),
137+
tolerance = 0.1
135138
)
136139
})
137140

@@ -174,11 +177,11 @@ test_that('stan intervals', {
174177
c(`1` = 0.0181025303127182, `2` = 0.0388665155739319, `3` = 0.0205886091162274,
175178
`4` = 0.0181715224502082, `5` = 0.00405145389896896)
176179

177-
expect_equivalent(confidence_parsnip$.pred_lower_good, stan_lower)
178-
expect_equivalent(confidence_parsnip$.pred_upper_good, stan_upper)
179-
expect_equivalent(confidence_parsnip$.pred_lower_bad, 1 - stan_upper)
180-
expect_equivalent(confidence_parsnip$.pred_upper_bad, 1 - stan_lower)
181-
expect_equivalent(confidence_parsnip$.std_error, stan_std)
180+
expect_equivalent(confidence_parsnip$.pred_lower_good, stan_lower, tolerance = 0.01)
181+
expect_equivalent(confidence_parsnip$.pred_upper_good, stan_upper, tolerance = 0.01)
182+
expect_equivalent(confidence_parsnip$.pred_lower_bad, 1 - stan_upper, tolerance = 0.01)
183+
expect_equivalent(confidence_parsnip$.pred_upper_bad, 1 - stan_lower, tolerance = 0.01)
184+
expect_equivalent(confidence_parsnip$.std_error, stan_std, tolerance = 0.001)
182185

183186
stan_pred_lower <- c(`1` = 0, `2` = 0, `3` = 0, `4` = 0, `5` = 1)
184187
stan_pred_upper <- c(`1` = 1, `2` = 1, `3` = 1, `4` = 1, `5` = 1)

0 commit comments

Comments
 (0)