Skip to content

Commit

Permalink
fix tests for CRAN
Browse files Browse the repository at this point in the history
  • Loading branch information
hbaniecki committed Sep 4, 2019
1 parent e5b1fd2 commit 99582f4
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 70 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
@@ -1,6 +1,6 @@
Package: modelStudio
Title: Interactive Studio with Explanations for ML Predictive Models
Version: 0.1.6
Version: 0.1.7
Authors@R:
c(person("Hubert", "Baniecki", role = c("aut", "cre"), email = "hbaniecki@gmail.com"),
person("Przemyslaw", "Biecek", role = c("aut"),
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
@@ -1,3 +1,6 @@
# modelStudio 0.1.7
* fix tests for CRAN

# modelStudio 0.1.6
Many minor changes stated in #20, most notably:
* rename `x` parameter to `object` in `modelStudio()`
Expand Down
2 changes: 1 addition & 1 deletion docs/articles/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/articles/vignette_modelStudio.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/authors.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion docs/news/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/modelStudio.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/modelStudioOptions.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions tests/testthat.R
@@ -1,4 +1,6 @@
library(testthat)
library(modelStudio)
library("testthat")
library("modelStudio")
library("DALEX")
library("randomForest")

test_check("modelStudio")
82 changes: 41 additions & 41 deletions tests/testthat/test_modelStudio.R
@@ -1,18 +1,18 @@
context("Check modelStudio() function")
library(DALEX)

source("test_objects.R")

ms1 <- modelStudio(explain_glm,
ms1 <- modelStudio::modelStudio(explain_glm,
new_observation = titanic_test[1,-9])

ms2 <- modelStudio(model_glm,
ms2 <- modelStudio::modelStudio(model_glm,
max_features = 5,
data = titanic_test[,-9],
y = titanic_test$survived == "yes",
new_observation = titanic_test[1:2,-9],
N = 50, B = 10)

ms3 <- modelStudio(model_glm,
ms3 <- modelStudio::modelStudio(model_glm,
max_features = 5,
facet_dim = c(2,3),
N = 150,
Expand All @@ -23,108 +23,108 @@ ms3 <- modelStudio(model_glm,
label = "xxx",
new_observation = titanic_test[1:10,-9])

ms4 <- modelStudio(explain_glm_numerical,
ms4 <- modelStudio::modelStudio(explain_glm_numerical,
new_observation = titanic_test[1:2, c(2,6,7,8)],
N = 50, B = 10)

ms5 <- modelStudio(explain_glm_not_numerical,
ms5 <- modelStudio::modelStudio(explain_glm_not_numerical,
new_observation = titanic_test[1:2, c(1,3,4,5)],
N = 50, B = 10)

ms6 <- modelStudio(explain_model_small,
ms6 <- modelStudio::modelStudio(explain_model_small,
new_observation = titanic_test[1:2, c(1,2)],
N = 50, B = 10)

ms_readme <- modelStudio(explain_titanic_glm,
ms_readme <- modelStudio::modelStudio(explain_titanic_glm,
new_observations,
facet_dim = c(2,2), N = 200, B = 20, time = 0)

ms_rf_apartments <- modelStudio(explain_rf,
ms_rf_apartments <- modelStudio::modelStudio(explain_rf,
new_observation = apartments[1:2,-1],
N = 50, B = 10, facet_dim = c(3,3),
time = 50, max_features = 4)

both_without_target <- modelStudio(model_titanic_glm,
both_without_target <- modelStudio::modelStudio(model_titanic_glm,
new_observation = nx,
N = 10,
B = 2,
data = x,
y = y)

both_full <- modelStudio(model_titanic_glm,
both_full <- modelStudio::modelStudio(model_titanic_glm,
new_observation = nz,
N = 10,
B = 2,
data = z,
y = y)

obs_without_target_data_full <- modelStudio(model_titanic_glm,
obs_without_target_data_full <- modelStudio::modelStudio(model_titanic_glm,
new_observation = nx,
N = 10,
B = 2,
data = z,
y = y)

obs_full_data_without_target <- modelStudio(model_titanic_glm,
obs_full_data_without_target <- modelStudio::modelStudio(model_titanic_glm,
new_observation = nz,
N = 10,
B = 2,
data = x,
y = y)

ms_big <- modelStudio(explain_artifficial,
ms_big <- modelStudio::modelStudio(explain_artifficial,
new_observation = artifficial[1:2,], N = 5, B = 2,
facet_dim = c(3,3))

ms_parallel <- modelStudio(explain_glm, new_observation = titanic_test[1:2,-9],
ms_parallel <- modelStudio::modelStudio(explain_glm, new_observation = titanic_test[1:2,-9],
N = 5, B = 2, parallel = TRUE)

ms_parallel_rf <- modelStudio(explain_rf, new_observation = apartments[1:5,-1],
ms_parallel_rf <- modelStudio::modelStudio(explain_rf, new_observation = apartments[1:5,-1],
N = 5, B = 2, parallel = TRUE)

# tests

test_that("explainer/model test", {
expect_is(ms1, "r2d3")
expect_is(ms2, "r2d3")
expect_is(ms3, "r2d3")
testthat::test_that("explainer/model test", {
testthat::expect_is(ms1, "r2d3")
testthat::expect_is(ms2, "r2d3")
testthat::expect_is(ms3, "r2d3")
})

test_that("only_numerical", {
expect_is(ms4, "r2d3")
testthat::test_that("only_numerical", {
testthat::expect_is(ms4, "r2d3")
})

test_that("only_not_numerical", {
expect_is(ms5, "r2d3")
testthat::test_that("only_not_numerical", {
testthat::expect_is(ms5, "r2d3")
})

test_that("description test, 2 features", {
expect_is(ms6, "r2d3")
testthat::test_that("description test, 2 features", {
testthat::expect_is(ms6, "r2d3")
})

test_that("README DEMO", {
expect_is(ms_readme, "r2d3")
testthat::test_that("README DEMO", {
testthat::expect_is(ms_readme, "r2d3")
})

test_that("randomForest apartments", {
expect_is(ms_rf_apartments, "r2d3")
testthat::test_that("randomForest apartments", {
testthat::expect_is(ms_rf_apartments, "r2d3")
})

test_that("test various possibilities of data and new obs", {
expect_is(both_full, "r2d3")
expect_is(both_without_target, "r2d3")
expect_is(obs_without_target_data_full, "r2d3")
expect_is(obs_full_data_without_target, "r2d3")
testthat::test_that("test various possibilities of data and new obs", {
testthat::expect_is(both_full, "r2d3")
testthat::expect_is(both_without_target, "r2d3")
testthat::expect_is(obs_without_target_data_full, "r2d3")
testthat::expect_is(obs_full_data_without_target, "r2d3")
})

test_that("more than 10 features", {
expect_is(ms_big, "r2d3")
testthat::test_that("more than 10 features", {
testthat::expect_is(ms_big, "r2d3")
})

test_that("parallel", {
expect_is(ms_parallel, "r2d3")
testthat::test_that("parallel", {
testthat::expect_is(ms_parallel, "r2d3")
})

test_that("parallel rf", {
expect_is(ms_parallel_rf, "r2d3")
testthat::test_that("parallel rf", {
testthat::expect_is(ms_parallel_rf, "r2d3")
})
18 changes: 9 additions & 9 deletions tests/testthat/test_modelStudioOptions.R
@@ -1,15 +1,15 @@
context("Check options parameter and modelStudioOptions() function")
library(DALEX)

source("test_objects.R")

op <- modelStudioOptions()
op <- modelStudio::modelStudioOptions()

test_that("modelStudioOptions()", {
expect_is(op, "list")
expect_true(length(op) > 30)
testthat::test_that("modelStudioOptions()", {
testthat::expect_is(op, "list")
testthat::expect_true(length(op) > 30)
})

new_options <- modelStudioOptions(
new_options <- modelStudio::modelStudioOptions(
scale_plot = FALSE,
show_subtitle = TRUE,
subtitle = "hello",
Expand Down Expand Up @@ -73,10 +73,10 @@ new_options <- modelStudioOptions(
fd_bar_color = NULL
)

ms <- modelStudio(explain_rf, apartments[1:2,],
ms <- modelStudio::modelStudio(explain_rf, apartments[1:2,],
facet_dim = c(2,3), N = 5, B = 2, show_info = FALSE,
options = new_options)

test_that("options parameter", {
expect_is(ms, "r2d3")
testthat::test_that("options parameter", {
testthat::expect_is(ms, "r2d3")
})
10 changes: 2 additions & 8 deletions tests/testthat/test_objects.R
@@ -1,8 +1,4 @@
# preparation
library("modelStudio")
library("DALEX")

titanic <- na.omit(titanic)
titanic <- na.omit(DALEX::titanic)
set.seed(1313)


Expand Down Expand Up @@ -61,9 +57,7 @@ explain_model_small <- DALEX::explain(model_small,

### randomForest + apartments

library("randomForest")

model_rf <- randomForest(m2.price ~. , data = apartments)
model_rf <- randomForest::randomForest(m2.price ~. , data = apartments)
explain_rf <- DALEX::explain(model_rf,
data = apartments,
y = apartments$m2.price, verbose = TRUE)
Expand Down

0 comments on commit 99582f4

Please sign in to comment.