Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests for Brulee engines #222

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

tests for Brulee engines #222

wants to merge 2 commits into from

Conversation

topepo
Copy link
Member

@topepo topepo commented Sep 13, 2024

# ------------------------------------------------------------------------------

is_torch_working <- function() {
res <- try(torch::torch_tensor(1), silent = TRUE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is causing a warning in R CMD check as an undeclared dependency, can we not just add torch to Suggests?

Comment on lines +1 to +30
library(modeldata)
library(rsample)

set.seed(392)
binary_tr <- sim_logistic(200, ~ .1 + 2 * A - 3 * B + 1 * A *B, corr = .7)
binary_rs <- vfold_cv(binary_tr)
binary_te <- sim_logistic(2, ~ .1 + 2 * A - 3 * B + 1 * A *B, corr = .7)

###

set.seed(392)
three_class_tr <-
sim_multinomial(
500,
~ -0.5 + 0.6 * abs(A),
~ ifelse(A > 0 & B > 0, 1.0 + 0.2 * A / B, - 2),
~ -0.6 * A + 0.50 * B - A * B)
three_class_rs <- vfold_cv(three_class_tr)
three_class_te <-
sim_multinomial(
2,
~ -0.5 + 0.6 * abs(A),
~ ifelse(A > 0 & B > 0, 1.0 + 0.2 * A / B, - 2),
~ -0.6 * A + 0.50 * B - A * B)

###

num_tr <- sim_regression(200)
num_rs <- vfold_cv(num_tr)
num_te <- sim_regression(2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This runs really fast, can we move all of this into functions?

@@ -0,0 +1,43 @@
test_that("linear regression via brulee", {
skip_if_not_installed("torch")
skip_if_not(any(get_from_env("linear_reg")$engine == "brulee"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these require a specific version of parsnip instead?

expect_true(nrow(ols_pred) == 2)
expect_named(ols_pred, ".pred")

# ------------------------------------------------------------------------------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you split these into two separate tests with more specific test descriptions, please? Applies to all tests with the # ---- separation header.

@hfrick hfrick marked this pull request as ready for review September 17, 2024 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants