@@ -138,6 +138,11 @@ test_that('svm rbf regression prediction', {
138
138
139
139
skip_if_not_installed(" kernlab" )
140
140
141
+ hpc_no_m <- hpc [- c(84 , 85 , 86 , 87 , 88 , 109 , 128 ),] %> %
142
+ droplevels()
143
+
144
+ ind <- c(2 , 1 , 143 )
145
+
141
146
reg_form <-
142
147
fit(
143
148
reg_mod ,
@@ -146,30 +151,30 @@ test_that('svm rbf regression prediction', {
146
151
control = ctrl
147
152
)
148
153
149
- # kern_pred <-
150
- # predict(reg_form$fit, hpc[1:3, -c(1, 5)]) %>%
151
- # as_tibble() %>%
152
- # setNames(".pred")
153
154
kern_pred <-
154
155
structure(
155
- list (.pred = c(5.02786147259765 , 4.81715220026091 , 4.86817852816449 )),
156
+ list (.pred = c(131.7743 , 372.0932 , 902.0633 )),
156
157
row.names = c(NA , - 3L ), class = c(" tbl_df" , " tbl" , " data.frame" ))
157
158
158
- parsnip_pred <- predict(reg_form , hpc [1 : 3 , - c(1 , 5 )])
159
- expect_equal(as.data.frame(kern_pred ), as.data.frame(parsnip_pred ))
159
+ parsnip_pred <- predict(reg_form , hpc [ind , - c(2 , 5 )])
160
+ expect_equal(as.data.frame(kern_pred ),
161
+ as.data.frame(parsnip_pred ),
162
+ tolerance = .0001 )
160
163
161
164
162
165
reg_xy_form <-
163
166
fit_xy(
164
167
reg_mod ,
165
- x = hpc [, 2 : 4 ],
168
+ x = hpc [, c( 1 , 3 , 4 ) ],
166
169
y = hpc $ input_fields ,
167
170
control = ctrl
168
171
)
169
172
expect_equal(reg_form $ fit @ alphaindex , reg_xy_form $ fit @ alphaindex )
170
173
171
- parsnip_xy_pred <- predict(reg_xy_form , hpc [1 : 3 , - c(1 , 5 )])
172
- expect_equal(as.data.frame(kern_pred ), as.data.frame(parsnip_xy_pred ))
174
+ parsnip_xy_pred <- predict(reg_xy_form , hpc [ind , - c(2 , 5 )])
175
+ expect_equal(as.data.frame(kern_pred ),
176
+ as.data.frame(parsnip_xy_pred ),
177
+ tolerance = .0001 )
173
178
})
174
179
175
180
# ------------------------------------------------------------------------------
@@ -178,12 +183,17 @@ test_that('svm rbf classification', {
178
183
179
184
skip_if_not_installed(" kernlab" )
180
185
186
+ hpc_no_m <- hpc [- c(84 , 85 , 86 , 87 , 88 , 109 , 128 ),] %> %
187
+ droplevels()
188
+
189
+ ind <- c(2 , 1 , 143 )
190
+
181
191
expect_error(
182
192
fit_xy(
183
193
cls_mod ,
184
194
control = ctrl ,
185
- x = hpc [, - 5 ],
186
- y = hpc $ class
195
+ x = hpc_no_m [, - 5 ],
196
+ y = hpc_no_m $ class
187
197
),
188
198
regexp = NA
189
199
)
@@ -192,7 +202,7 @@ test_that('svm rbf classification', {
192
202
fit(
193
203
cls_mod ,
194
204
class ~ . ,
195
- data = hpc ,
205
+ data = hpc_no_m ,
196
206
control = ctrl
197
207
),
198
208
regexp = NA
@@ -205,58 +215,50 @@ test_that('svm rbf classification probabilities', {
205
215
206
216
skip_if_not_installed(" kernlab" )
207
217
208
- ind <- c(1 , 51 , 101 )
218
+ hpc_no_m <- hpc [- c(84 , 85 , 86 , 87 , 88 , 109 , 128 ),] %> %
219
+ droplevels()
220
+
221
+ ind <- c(4 , 55 , 143 )
209
222
210
223
set.seed(34562 )
211
224
cls_form <-
212
225
fit(
213
226
cls_mod ,
214
227
class ~ . ,
215
- data = hpc ,
228
+ data = hpc_no_m ,
216
229
control = ctrl
217
230
)
218
231
219
- # kern_class <-
220
- # tibble(.pred_class = predict(cls_form$fit, hpc[ind, -5]))
221
-
222
232
kern_class <-
223
233
structure(list (
224
234
.pred_class = structure(
225
- c(1L , 3L , 3L ),
226
- .Label = c(" setosa " , " versicolor " , " virginica " ), class = " factor" )),
235
+ c(1L , 1L , 3L ),
236
+ .Label = c(" VF " , " F " , " L " ), class = " factor" )),
227
237
row.names = c(NA , - 3L ), class = c(" tbl_df" , " tbl" , " data.frame" ))
228
238
229
- parsnip_class <- predict(cls_form , hpc [ind , - 5 ])
239
+ parsnip_class <- predict(cls_form , hpc_no_m [ind , - 5 ])
230
240
expect_equal(kern_class , parsnip_class )
231
241
232
242
set.seed(34562 )
233
243
cls_xy_form <-
234
244
fit_xy(
235
245
cls_mod ,
236
- x = hpc [, 1 : 4 ],
237
- y = hpc $ class ,
246
+ x = hpc_no_m [, 1 : 4 ],
247
+ y = hpc_no_m $ class ,
238
248
control = ctrl
239
249
)
240
250
expect_equal(cls_form $ fit @ alphaindex , cls_xy_form $ fit @ alphaindex )
241
251
242
252
library(kernlab )
243
253
kern_probs <-
244
- kernlab :: predict(cls_form $ fit , hpc [ind , - 5 ], type = " probabilities" ) %> %
254
+ kernlab :: predict(cls_form $ fit , hpc_no_m [ind , - 5 ], type = " probabilities" ) %> %
245
255
as_tibble() %> %
246
- setNames(c(' .pred_setosa' , ' .pred_versicolor' , ' .pred_virginica' ))
247
-
248
- # kern_probs <-
249
- # structure(
250
- # list(
251
- # .pred_setosa = c(0.985403715135807, 0.0158818274678279, 0.00633995479908973),
252
- # .pred_versicolor = c(0.00818691538722139, 0.359005663318986, 0.0173471664171275),
253
- # .pred_virginica = c(0.00640936947697121, 0.625112509213187, 0.976312878783783)),
254
- # row.names = c(NA,-3L), class = c("tbl_df", "tbl", "data.frame"))
256
+ setNames(c(' .pred_VF' , ' .pred_F' , ' .pred_L' ))
255
257
256
- parsnip_probs <- predict(cls_form , hpc [ind , - 5 ], type = " prob" )
258
+ parsnip_probs <- predict(cls_form , hpc_no_m [ind , - 5 ], type = " prob" )
257
259
expect_equal(as.data.frame(kern_probs ), as.data.frame(parsnip_probs ))
258
260
259
- parsnip_xy_probs <- predict(cls_xy_form , hpc [ind , - 5 ], type = " prob" )
261
+ parsnip_xy_probs <- predict(cls_xy_form , hpc_no_m [ind , - 5 ], type = " prob" )
260
262
expect_equal(as.data.frame(kern_probs ), as.data.frame(parsnip_xy_probs ))
261
263
})
262
264
0 commit comments