dataspelunking / MLwR

Machine Learning with R
228 stars 419 forks source link

train function from chapter 11 does not work #4

Closed RaymondBalise closed 5 years ago

RaymondBalise commented 5 years ago

With R 3.5.3 running caret 6.0-84. The chunk of code below (around line 61 on GITHUB)

library(ipred)
library(caret)

set.seed(300)

ctrl <- trainControl(method = "cv", number = 10)

bagctrl <- bagControl(fit = svmBag$fit,
                      predict = svmBag$pred,
                      aggregate = svmBag$aggregate)

svmbag <- train(default ~ ., data = credit, "bag",
                trControl = ctrl, bagControl = bagctrl)

throws this warning 10 times:

10: model fit failed for Fold10: vars=35 Error in fitter(btSamples[[iter]], x = x, y = y, ctrl = bagControl, v = vars,  : 
  task 1 failed - "no applicable method for 'predict' applied to an object of class "c('ksvm', 'vm')""

Then this

11: In nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo,  ... :
  There were missing values in resampled performance measures.

Help....

dataspelunking commented 5 years ago

This particular block of code has been such a continual source of reader issues that I removed it from the 3rd edition.

The caret package seems to have changed at some point, and as hard as I've tried, I can no longer get the custom bagging function to work consistently.

It should be possible to get this working by writing custom functions for fit, predict, and aggregate, but this is outside the scope of the book.