Skip to content

Commit 44f2f81

Browse files
committed
add sparse_hotel_rates() helper function
1 parent 6e2fb00 commit 44f2f81

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/testthat/helper-objects.R

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,30 @@ is_tf_ok <- function() {
2424
}
2525
res
2626
}
27+
28+
# ------------------------------------------------------------------------------
29+
# For sparse tibble testing
30+
31+
sparse_hotel_rates <- function() {
32+
# 99.2 sparsity
33+
hotel_rates <- modeldata::hotel_rates
34+
35+
prefix_colnames <- function(x, prefix) {
36+
colnames(x) <- paste(colnames(x), prefix, sep = "_")
37+
x
38+
}
39+
40+
dummies_country <- hardhat::fct_encode_one_hot(hotel_rates$country)
41+
dummies_company <- hardhat::fct_encode_one_hot(hotel_rates$company)
42+
dummies_agent <- hardhat::fct_encode_one_hot(hotel_rates$agent)
43+
44+
res <- dplyr::bind_cols(
45+
hotel_rates["avg_price_per_room"],
46+
prefix_colnames(dummies_country, "country"),
47+
prefix_colnames(dummies_company, "company"),
48+
prefix_colnames(dummies_agent, "agent")
49+
)
50+
51+
res <- as.matrix(res)
52+
Matrix::Matrix(res, sparse = TRUE)
53+
}

0 commit comments

Comments
 (0)