1- library(modeldata )
2-
3- data(" wa_churn" )
4- data(" lending_club" )
5- data(" hpc_data" )
6-
7- # ------------------------------------------------------------------------------
81
92ctrl <- control_parsnip(verbosity = 1 , catch = FALSE )
103caught_ctrl <- control_parsnip(verbosity = 1 , catch = TRUE )
@@ -25,53 +18,64 @@ is_tf_ok <- function() {
2518 res
2619}
2720
28- # ------------------------------------------------------------------------------
29- # for quantile regression tests
21+ if ( rlang :: is_installed( " modeldata " )) {
22+ # ------------------------------------------------------------------------------
3023
31- data( " Sacramento " )
24+ library( modeldata )
3225
33- Sacramento_small <-
34- modeldata :: Sacramento | >
35- dplyr :: mutate( price = log10( price )) | >
36- dplyr :: select( price , beds , baths , sqft , latitude , longitude )
26+ data( " wa_churn " )
27+ data( " lending_club " )
28+ data( " hpc_data " )
29+ data( two_class_dat , package = " modeldata " )
3730
38- sac_train <- Sacramento_small [ - ( 1 : 5 ), ]
39- sac_test <- Sacramento_small [ 1 : 5 , ]
31+ # ------------------------------------------------------------------------------
32+ # for quantile regression tests
4033
41- # ------------------------------------------------------------------------------
42- # For sparse tibble testing
34+ data(" Sacramento" )
4335
44- sparse_hotel_rates <- function (tibble = FALSE ) {
45- # 99.2 sparsity
46- hotel_rates <- modeldata :: hotel_rates
36+ Sacramento_small <-
37+ modeldata :: Sacramento | >
38+ dplyr :: mutate(price = log10(price )) | >
39+ dplyr :: select(price , beds , baths , sqft , latitude , longitude )
4740
48- prefix_colnames <- function (x , prefix ) {
49- colnames(x ) <- paste(colnames(x ), prefix , sep = " _" )
50- x
51- }
41+ sac_train <- Sacramento_small [- (1 : 5 ), ]
42+ sac_test <- Sacramento_small [ 1 : 5 , ]
5243
53- dummies_country <- hardhat :: fct_encode_one_hot(hotel_rates $ country )
54- dummies_company <- hardhat :: fct_encode_one_hot(hotel_rates $ company )
55- dummies_agent <- hardhat :: fct_encode_one_hot(hotel_rates $ agent )
44+ # ------------------------------------------------------------------------------
45+ # For sparse tibble testing
5646
57- res <- dplyr :: bind_cols(
58- hotel_rates [" avg_price_per_room" ],
59- prefix_colnames(dummies_country , " country" ),
60- prefix_colnames(dummies_company , " company" ),
61- prefix_colnames(dummies_agent , " agent" )
62- )
47+ sparse_hotel_rates <- function (tibble = FALSE ) {
48+ # 99.2 sparsity
49+ hotel_rates <- modeldata :: hotel_rates
6350
64- res <- as.matrix(res )
65- res <- Matrix :: Matrix(res , sparse = TRUE )
51+ prefix_colnames <- function (x , prefix ) {
52+ colnames(x ) <- paste(colnames(x ), prefix , sep = " _" )
53+ x
54+ }
6655
67- if (tibble ) {
68- res <- sparsevctrs :: coerce_to_sparse_tibble(res )
56+ dummies_country <- hardhat :: fct_encode_one_hot(hotel_rates $ country )
57+ dummies_company <- hardhat :: fct_encode_one_hot(hotel_rates $ company )
58+ dummies_agent <- hardhat :: fct_encode_one_hot(hotel_rates $ agent )
6959
70- # materialize outcome
71- withr :: local_options(" sparsevctrs.verbose_materialize" = NULL )
72- res $ avg_price_per_room <- res $ avg_price_per_room []
73- }
60+ res <- dplyr :: bind_cols(
61+ hotel_rates [" avg_price_per_room" ],
62+ prefix_colnames(dummies_country , " country" ),
63+ prefix_colnames(dummies_company , " company" ),
64+ prefix_colnames(dummies_agent , " agent" )
65+ )
7466
75- res
67+ res <- as.matrix(res )
68+ res <- Matrix :: Matrix(res , sparse = TRUE )
69+
70+ if (tibble ) {
71+ res <- sparsevctrs :: coerce_to_sparse_tibble(res )
72+
73+ # materialize outcome
74+ withr :: local_options(" sparsevctrs.verbose_materialize" = NULL )
75+ res $ avg_price_per_room <- res $ avg_price_per_room []
76+ }
77+
78+ res
79+ }
7680}
7781
0 commit comments