1
1
test_that(" sparse matrices can be passed to `fit_xy()" , {
2
+ skip_if_not_installed(" LiblineaR" )
3
+
2
4
hotel_data <- sparse_hotel_rates()
3
5
4
- lm_spec <- linear_reg(penalty = 0 ) %> %
5
- set_engine(" glmnet" )
6
+ spec <- svm_linear() %> %
7
+ set_mode(" regression" ) %> %
8
+ set_engine(" LiblineaR" )
6
9
7
10
expect_no_error(
8
- lm_fit <- fit_xy(lm_spec , x = hotel_data [, - 1 ], y = hotel_data [, 1 ])
11
+ lm_fit <- fit_xy(spec , x = hotel_data [, - 1 ], y = hotel_data [, 1 ])
9
12
)
10
13
})
11
14
12
15
test_that(" to_sparse_data_frame() is used correctly" , {
16
+ skip_if_not_installed(" LiblineaR" )
17
+
13
18
local_mocked_bindings(
14
19
to_sparse_data_frame = function (x , object ) {
15
20
if (methods :: is(x , " sparseMatrix" )) {
@@ -25,28 +30,31 @@ test_that("to_sparse_data_frame() is used correctly", {
25
30
26
31
hotel_data <- sparse_hotel_rates()
27
32
28
- lm_spec <- linear_reg(penalty = 0 ) %> %
33
+ spec <- linear_reg() %> %
29
34
set_engine(" lm" )
30
35
31
36
expect_snapshot(
32
37
error = TRUE ,
33
- fit_xy(lm_spec , x = mtcars [, - 1 ], y = mtcars [, 1 ])
38
+ fit_xy(spec , x = mtcars [, - 1 ], y = mtcars [, 1 ])
34
39
)
35
40
expect_snapshot(
36
41
error = TRUE ,
37
- fit_xy(lm_spec , x = hotel_data [, - 1 ], y = hotel_data [, 1 ])
42
+ fit_xy(spec , x = hotel_data [, - 1 ], y = hotel_data [, 1 ])
38
43
)
39
44
40
- lm_spec <- linear_reg(penalty = 0 ) %> %
41
- set_engine(" glmnet" )
45
+ spec <- svm_linear() %> %
46
+ set_mode(" regression" ) %> %
47
+ set_engine(" LiblineaR" )
42
48
43
49
expect_snapshot(
44
50
error = TRUE ,
45
- fit_xy(lm_spec , x = hotel_data [, - 1 ], y = hotel_data [, 1 ])
51
+ fit_xy(spec , x = hotel_data [, - 1 ], y = hotel_data [, 1 ])
46
52
)
47
53
})
48
54
49
55
test_that(" maybe_sparse_matrix() is used correctly" , {
56
+ skip_if_not_installed(" LiblineaR" )
57
+
50
58
local_mocked_bindings(
51
59
maybe_sparse_matrix = function (x ) {
52
60
if (any(vapply(x , sparsevctrs :: is_sparse_vector , logical (1 )))) {
@@ -59,23 +67,24 @@ test_that("maybe_sparse_matrix() is used correctly", {
59
67
60
68
hotel_data <- sparse_hotel_rates()
61
69
62
- lm_spec <- linear_reg(penalty = 0 ) %> %
63
- set_engine(" glmnet" )
70
+ spec <- svm_linear() %> %
71
+ set_mode(" regression" ) %> %
72
+ set_engine(" LiblineaR" )
64
73
65
74
expect_snapshot(
66
75
error = TRUE ,
67
- fit_xy(lm_spec , x = hotel_data [, - 1 ], y = hotel_data [, 1 ])
76
+ fit_xy(spec , x = hotel_data [, - 1 ], y = hotel_data [, 1 ])
68
77
)
69
78
expect_snapshot(
70
79
error = TRUE ,
71
- fit_xy(lm_spec , x = mtcars [, - 1 ], y = mtcars [, 1 ])
80
+ fit_xy(spec , x = mtcars [, - 1 ], y = mtcars [, 1 ])
72
81
)
73
82
expect_snapshot(
74
83
error = TRUE ,
75
- fit_xy(lm_spec , x = as.data.frame(mtcars )[, - 1 ], y = as.data.frame(mtcars )[, 1 ])
84
+ fit_xy(spec , x = as.data.frame(mtcars )[, - 1 ], y = as.data.frame(mtcars )[, 1 ])
76
85
)
77
86
expect_snapshot(
78
87
error = TRUE ,
79
- fit_xy(lm_spec , x = tibble :: as_tibble(mtcars )[, - 1 ], y = tibble :: as_tibble(mtcars )[, 1 ])
88
+ fit_xy(spec , x = tibble :: as_tibble(mtcars )[, - 1 ], y = tibble :: as_tibble(mtcars )[, 1 ])
80
89
)
81
90
})
0 commit comments