@@ -138,6 +138,11 @@ test_that('svm rbf regression prediction', {
138138
139139 skip_if_not_installed(" kernlab" )
140140
141+ hpc_no_m <- hpc [- c(84 , 85 , 86 , 87 , 88 , 109 , 128 ),] %> %
142+ droplevels()
143+
144+ ind <- c(2 , 1 , 143 )
145+
141146 reg_form <-
142147 fit(
143148 reg_mod ,
@@ -146,30 +151,30 @@ test_that('svm rbf regression prediction', {
146151 control = ctrl
147152 )
148153
149- # kern_pred <-
150- # predict(reg_form$fit, hpc[1:3, -c(1, 5)]) %>%
151- # as_tibble() %>%
152- # setNames(".pred")
153154 kern_pred <-
154155 structure(
155- list (.pred = c(5.02786147259765 , 4.81715220026091 , 4.86817852816449 )),
156+ list (.pred = c(131.7743 , 372.0932 , 902.0633 )),
156157 row.names = c(NA , - 3L ), class = c(" tbl_df" , " tbl" , " data.frame" ))
157158
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 )
160163
161164
162165 reg_xy_form <-
163166 fit_xy(
164167 reg_mod ,
165- x = hpc [, 2 : 4 ],
168+ x = hpc [, c( 1 , 3 , 4 ) ],
166169 y = hpc $ input_fields ,
167170 control = ctrl
168171 )
169172 expect_equal(reg_form $ fit @ alphaindex , reg_xy_form $ fit @ alphaindex )
170173
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 )
173178})
174179
175180# ------------------------------------------------------------------------------
@@ -178,12 +183,17 @@ test_that('svm rbf classification', {
178183
179184 skip_if_not_installed(" kernlab" )
180185
186+ hpc_no_m <- hpc [- c(84 , 85 , 86 , 87 , 88 , 109 , 128 ),] %> %
187+ droplevels()
188+
189+ ind <- c(2 , 1 , 143 )
190+
181191 expect_error(
182192 fit_xy(
183193 cls_mod ,
184194 control = ctrl ,
185- x = hpc [, - 5 ],
186- y = hpc $ class
195+ x = hpc_no_m [, - 5 ],
196+ y = hpc_no_m $ class
187197 ),
188198 regexp = NA
189199 )
@@ -192,7 +202,7 @@ test_that('svm rbf classification', {
192202 fit(
193203 cls_mod ,
194204 class ~ . ,
195- data = hpc ,
205+ data = hpc_no_m ,
196206 control = ctrl
197207 ),
198208 regexp = NA
@@ -205,58 +215,50 @@ test_that('svm rbf classification probabilities', {
205215
206216 skip_if_not_installed(" kernlab" )
207217
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 )
209222
210223 set.seed(34562 )
211224 cls_form <-
212225 fit(
213226 cls_mod ,
214227 class ~ . ,
215- data = hpc ,
228+ data = hpc_no_m ,
216229 control = ctrl
217230 )
218231
219- # kern_class <-
220- # tibble(.pred_class = predict(cls_form$fit, hpc[ind, -5]))
221-
222232 kern_class <-
223233 structure(list (
224234 .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" )),
227237 row.names = c(NA , - 3L ), class = c(" tbl_df" , " tbl" , " data.frame" ))
228238
229- parsnip_class <- predict(cls_form , hpc [ind , - 5 ])
239+ parsnip_class <- predict(cls_form , hpc_no_m [ind , - 5 ])
230240 expect_equal(kern_class , parsnip_class )
231241
232242 set.seed(34562 )
233243 cls_xy_form <-
234244 fit_xy(
235245 cls_mod ,
236- x = hpc [, 1 : 4 ],
237- y = hpc $ class ,
246+ x = hpc_no_m [, 1 : 4 ],
247+ y = hpc_no_m $ class ,
238248 control = ctrl
239249 )
240250 expect_equal(cls_form $ fit @ alphaindex , cls_xy_form $ fit @ alphaindex )
241251
242252 library(kernlab )
243253 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" ) %> %
245255 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' ))
255257
256- parsnip_probs <- predict(cls_form , hpc [ind , - 5 ], type = " prob" )
258+ parsnip_probs <- predict(cls_form , hpc_no_m [ind , - 5 ], type = " prob" )
257259 expect_equal(as.data.frame(kern_probs ), as.data.frame(parsnip_probs ))
258260
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" )
260262 expect_equal(as.data.frame(kern_probs ), as.data.frame(parsnip_xy_probs ))
261263})
262264
0 commit comments