Skip to content

Commit 0d80715

Browse files
authored
Merge pull request #333 from simonpcouch/master
Write out iris with modeldata::hpc_data
2 parents aab7e0c + 592ab0e commit 0d80715

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+736
-691
lines changed

R/descriptors.R

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,28 @@
2626
#' column, `..y`.
2727
#' }
2828
#'
29-
#' For example, if you use the model formula `Sepal.Width ~ .` with the `iris`
30-
#' data, the values would be
29+
#' For example, if you use the model formula `circumference ~ .` with the
30+
#' built-in `Orange` data, the values would be
3131
#' \preformatted{
32-
#' .preds() = 4 (the 4 columns in `iris`)
33-
#' .cols() = 5 (3 numeric columns + 2 from Species dummy variables)
34-
#' .obs() = 150
32+
#' .preds() = 2 (the 2 remaining columns in `Orange`)
33+
#' .cols() = 5 (1 numeric column + 4 from Tree dummy variables)
34+
#' .obs() = 35
3535
#' .lvls() = NA (no factor outcome)
36-
#' .facts() = 1 (the Species predictor)
37-
#' .y() = <vector> (Sepal.Width as a vector)
38-
#' .x() = <data.frame> (The other 4 columns as a data frame)
36+
#' .facts() = 1 (the Tree predictor)
37+
#' .y() = <vector> (circumference as a vector)
38+
#' .x() = <data.frame> (The other 2 columns as a data frame)
3939
#' .dat() = <data.frame> (The full data set)
4040
#' }
4141
#'
42-
#' If the formula `Species ~ .` where used:
42+
#' If the formula `Tree ~ .` were used:
4343
#' \preformatted{
44-
#' .preds() = 4 (the 4 numeric columns in `iris`)
45-
#' .cols() = 4 (same)
46-
#' .obs() = 150
47-
#' .lvls() = c(setosa = 50, versicolor = 50, virginica = 50)
44+
#' .preds() = 2 (the 2 numeric columns in `Orange`)
45+
#' .cols() = 2 (same)
46+
#' .obs() = 35
47+
#' .lvls() = c("1" = 7, "2" = 7, "3" = 7, "4" = 7, "5" = 7)
4848
#' .facts() = 0
49-
#' .y() = <vector> (Species as a vector)
50-
#' .x() = <data.frame> (The other 4 columns as a data frame)
49+
#' .y() = <vector> (Tree as a vector)
50+
#' .x() = <data.frame> (The other 2 columns as a data frame)
5151
#' .dat() = <data.frame> (The full data set)
5252
#' }
5353
#'

R/model_object_docs.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,18 @@
5353
#' `parsnip` model functions do not do this. For example, using
5454
#'
5555
#'\preformatted{
56-
#' rand_forest(mtry = ncol(iris) - 1)
56+
#' rand_forest(mtry = ncol(mtcars) - 1)
5757
#' }
5858
#'
59-
#' **does not** execute `ncol(iris) - 1` when creating the specification.
59+
#' **does not** execute `ncol(mtcars) - 1` when creating the specification.
6060
#' This can be seen in the output:
6161
#'
6262
#'\preformatted{
63-
#' > rand_forest(mtry = ncol(iris) - 1)
63+
#' > rand_forest(mtry = ncol(mtcars) - 1)
6464
#' Random Forest Model Specification (unknown)
6565
#'
6666
#' Main Arguments:
67-
#' mtry = ncol(iris) - 1
67+
#' mtry = ncol(mtcars) - 1
6868
#'}
6969
#'
7070
#' The model functions save the argument _expressions_ and their
@@ -102,14 +102,14 @@
102102
#' object is small. For example, using
103103
#'
104104
#'\preformatted{
105-
#' rand_forest(mtry = ncol(!!iris) - 1)
105+
#' rand_forest(mtry = ncol(!!mtcars) - 1)
106106
#' }
107107
#'
108108
#' would work (and be reproducible between sessions) but embeds
109-
#' the entire iris data set into the `mtry` expression:
109+
#' the entire mtcars data set into the `mtry` expression:
110110
#'
111111
#'\preformatted{
112-
#' > rand_forest(mtry = ncol(!!iris) - 1)
112+
#' > rand_forest(mtry = ncol(!!mtcars) - 1)
113113
#' Random Forest Model Specification (unknown)
114114
#'
115115
#' Main Arguments:
@@ -120,14 +120,14 @@
120120
#' it, this wouldn't be too bad:
121121
#'
122122
#'\preformatted{
123-
#' > mtry_val <- ncol(iris) - 1
123+
#' > mtry_val <- ncol(mtcars) - 1
124124
#' > mtry_val
125-
#' [1] 4
125+
#' [1] 10
126126
#' > rand_forest(mtry = !!mtry_val)
127127
#' Random Forest Model Specification (unknown)
128128
#'
129129
#' Main Arguments:
130-
#' mtry = 4
130+
#' mtry = 10
131131
#'}
132132
#'
133133
#' More information on quosures and quasiquotation can be found at

R/nullmodel.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ null_model <-
182182
#' @return A tibble with column `value`.
183183
#' @export
184184
#' @examples
185-
#' nullmodel(iris[,-5], iris$Species) %>% tidy()
186185
#'
187186
#' nullmodel(mtcars[,-1], mtcars$mpg) %>% tidy()
188187

man/descriptors.Rd

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/model_spec.Rd

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/tidy.nullmodel.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/helper-objects.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ library(modeldata)
22

33
data("wa_churn")
44
data("lending_club")
5+
data("hpc_data")
56

67
# ------------------------------------------------------------------------------
78

tests/testthat/test_adds.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ library(dplyr)
44

55
context("adding functions")
66
source("helpers.R")
7+
source(test_path("helper-objects.R"))
8+
hpc <- hpc_data[1:150, c(2:5, 8)]
79

810
# ------------------------------------------------------------------------------
911

1012
test_that('adding row indicies', {
11-
iris_2 <- iris %>% add_rowindex()
12-
expect_true(nrow(iris_2) == 150)
13-
expect_true(sum(names(iris_2) == ".row") == 1)
14-
expect_true(is.integer(iris_2$.row))
13+
hpc_2 <- hpc %>% add_rowindex()
14+
expect_true(nrow(hpc_2) == 150)
15+
expect_true(sum(names(hpc_2) == ".row") == 1)
16+
expect_true(is.integer(hpc_2$.row))
1517

1618
mtcar_2 <- dplyr::as_tibble(mtcars) %>% dplyr::slice(0) %>% add_rowindex()
1719
expect_true(nrow(mtcar_2) == 0)

tests/testthat/test_boost_tree.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ library(rlang)
66

77
context("boosted trees")
88
source("helpers.R")
9+
source(test_path("helper-objects.R"))
10+
hpc <- hpc_data[1:150, c(2:5, 8)]
911

1012
# ------------------------------------------------------------------------------
1113

@@ -134,11 +136,11 @@ test_that('bad input', {
134136
expect_error(boost_tree(mode = "bogus"))
135137
expect_error({
136138
bt <- boost_tree(trees = -1) %>% set_engine("xgboost")
137-
fit(bt, Species ~ ., iris)
139+
fit(bt, class ~ ., hpc)
138140
})
139141
expect_error({
140142
bt <- boost_tree(min_n = -10) %>% set_engine("xgboost")
141-
fit(bt, Species ~ ., iris)
143+
fit(bt, class ~ ., hpc)
142144
})
143145
expect_message(translate(boost_tree(mode = "classification"), engine = NULL))
144146
expect_error(translate(boost_tree(formula = y ~ x)))

tests/testthat/test_boost_tree_spark.R

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ library(dplyr)
66

77
context("boosted tree execution with spark")
88
source(test_path("helper-objects.R"))
9+
hpc <- hpc_data[1:150, c(2:5, 8)]
910

1011
# ------------------------------------------------------------------------------
1112

1213
test_that('spark execution', {
1314

1415
skip_if_not_installed("sparklyr")
15-
1616
library(sparklyr)
1717

1818
sc <- try(spark_connect(master = "local"), silent = TRUE)
1919

2020
skip_if(inherits(sc, "try-error"))
2121

22-
iris_bt_tr <- copy_to(sc, iris[-(1:4), ], "iris_bt_tr", overwrite = TRUE)
23-
iris_bt_te <- copy_to(sc, iris[ 1:4 , -1], "iris_bt_te", overwrite = TRUE)
22+
hpc_bt_tr <- copy_to(sc, hpc[-(1:4), ], "hpc_bt_tr", overwrite = TRUE)
23+
hpc_bt_te <- copy_to(sc, hpc[ 1:4 , -1], "hpc_bt_te", overwrite = TRUE)
2424

2525
# ----------------------------------------------------------------------------
2626

@@ -30,8 +30,8 @@ test_that('spark execution', {
3030
boost_tree(trees = 5, mode = "regression") %>%
3131
set_engine("spark", seed = 12),
3232
control = ctrl,
33-
Sepal_Length ~ .,
34-
data = iris_bt_tr
33+
class ~ .,
34+
data = hpc_bt_tr
3535
),
3636
regexp = NA
3737
)
@@ -43,29 +43,29 @@ test_that('spark execution', {
4343
boost_tree(trees = 5, mode = "regression") %>%
4444
set_engine("spark", seed = 12),
4545
control = ctrl,
46-
Sepal_Length ~ .,
47-
data = iris_bt_tr
46+
compounds ~ .,
47+
data = hpc_bt_tr
4848
),
4949
regexp = NA
5050
)
5151

5252
expect_error(
53-
spark_reg_pred <- predict(spark_reg_fit, iris_bt_te),
53+
spark_reg_pred <- predict(spark_reg_fit, hpc_bt_te),
5454
regexp = NA
5555
)
5656

5757
expect_error(
58-
spark_reg_pred_num <- parsnip:::predict_numeric.model_fit(spark_reg_fit, iris_bt_te),
58+
spark_reg_pred_num <- parsnip:::predict_numeric.model_fit(spark_reg_fit, hpc_bt_te),
5959
regexp = NA
6060
)
6161

6262
expect_error(
63-
spark_reg_dup <- predict(spark_reg_fit_dup, iris_bt_te),
63+
spark_reg_dup <- predict(spark_reg_fit_dup, hpc_bt_te),
6464
regexp = NA
6565
)
6666

6767
expect_error(
68-
spark_reg_num_dup <- parsnip:::predict_numeric.model_fit(spark_reg_fit_dup, iris_bt_te),
68+
spark_reg_num_dup <- parsnip:::predict_numeric.model_fit(spark_reg_fit_dup, hpc_bt_te),
6969
regexp = NA
7070
)
7171

0 commit comments

Comments
 (0)