mlr-org / mlr3book

Online version of Bischl, B., Sonabend, R., Kotthoff, L., & Lang, M. (Eds.). (2024). "Applied Machine Learning Using mlr3 in R". CRC Press.
https://mlr3book.mlr-org.com/
MIT License
255 stars 59 forks source link

Chapter 4.1 Example bug #811

Closed einabadi-sh closed 10 months ago

einabadi-sh commented 10 months ago

This is the first example of model tuning in chapter 4.1. Despite attempting it with various settings, I continually encounter the same error. It appears that the function might not be supplying the correct data frame to the predictor.

library(mlr3verse)
tsk_sonar = tsk("sonar")

learner = lrn("classif.svm",
              cost  = to_tune(1e-1, 1e5),
              gamma = to_tune(1e-1, 1),
              kernel = "radial",
              type = "C-classification"
)

instance = ti(
  task = tsk_sonar,
  learner = learner,
  resampling = rsmp("cv", folds = 3),
  measures = msr("classif.ce"),
  terminator = trm("none")
)

tuner = tnr("grid_search", resolution = 5, batch_size = 10)
tuner$optimize(instance)

Error in predict.svm(self$model, newdata = newdata, probability = (self$predict_type == : test data does not match model !

larskotthoff commented 10 months ago

Works for me. Can you post your package versions please?

einabadi-sh commented 10 months ago

Ubuntu 22.04.3 LTS

R.version.string [1] "R version 4.3.2 (2023-10-31)"

packageVersion("mlr3verse") [1] ‘0.2.8’

Thanks

larskotthoff commented 10 months ago

Same version here. What about the other packages?

einabadi-sh commented 10 months ago

Screenshot from 2024-01-26 16-55-46

einabadi-sh commented 10 months ago

packageVersion("e1071") [1] ‘1.7.13’

larskotthoff commented 10 months ago

Looks like you installed some github versions? Can you try the latest CRAN versions please?

einabadi-sh commented 10 months ago
Screenshot 2024-01-26 at 6 28 43 PM
einabadi-sh commented 10 months ago

thanks, now it works!