mlr-org / mlr3learners

Recommended learners for mlr3
https://mlr3learners.mlr-org.com
GNU Lesser General Public License v3.0
91 stars 15 forks source link

Can't set 'cost' parameter in 'regr.svm' learner for 'nu-regression' #208

Closed edsantor closed 3 years ago

edsantor commented 3 years ago

I reopen this issue to demonstrate with the iris data that it is possible to set the cost parameter with nu-regression using the e1071 package directly. However, within mlr3 with regr.svm learner this is not possible and returns an error for nu-regression. The influence of cost on the RMSE can be observed in the following plot:

library(mlr3measures)
data("iris")

iris = subset(iris, Species == "versicolor")

library(e1071)

cost = seq(1,80,2)
RMSEsvm = c()

for (i in cost) {

  fit = svm(
    Petal.Length ~ Petal.Width,
    data = iris,
    type = "nu-regression",
    kernel = "radial",
    gamma = 1,
    cost = i,
    epsilon = 0.1,
    nu = 0.1
  )

  y_hat = predict(
    object = fit,
    newdata = iris
  )

  RMSEsvm =c(RMSEsvm, rmse(
    truth = iris$Petal.Length,
    response = y_hat
  ))
}

plot(
  x = cost,
  y = RMSEsvm,
  pch = 16
)

The error returned in the learner definition is shown below:

learner_svm = lrn("regr.svm")

learner_svm$param_set$values = list(
  type = "nu-regression",
  kernel = "radial",
  cost = 1000,
  gamma = 1,
  epsilon = 0.1
)

Error in self$assert(xs) : Assertion on 'xs' failed: The parameter 'cost' can only be set if the following condition is met 'type = eps-regression'. Instead the current parameter value is: type=nu-regression.

The same error is returned using the kernlab package with the regr.ksvm learner:

The parameter 'C' can only be set if the following condition is met 'type <U+2208> {eps-svr, eps-bsvr}'. Instead the current parameter value is: type=nu-svr.

Please research this question before giving an answer. Thank you very much.

edsantor commented 3 years ago

I've done some more research and I think the following dependencies are not correct:

cost epsilon

Both cost and epsilon are required parameters also for nu-regression (Schölkopf et. al, 2000).

Can I remove these dependencies on my pc? Someone help me?

RaphaelS1 commented 3 years ago

Fixed ksvm in mlr3extralearners https://github.com/mlr-org/mlr3extralearners/pull/116

pat-s commented 3 years ago

Hi @edsantor

Thanks for posting a reproducible example. I've checked and I think you are right, cost should also allow nu-regression. I think the answer of @larskotthoff was a bit too hasty in https://github.com/mlr-org/mlr3learners/issues/207#issuecomment-932008669.

pat-s commented 3 years ago

For a short term fix you can install {mlr3learners} from the branch via remotes::install_github("mlr-org/mlr3learners@c-nu-regr"). Alternatively you can also use the fixed ksvm learner in {mlr3exterlearners}.

The fix will be included in the next CRAN release.

Sorry for all the troubles you had with this issue and all the rejections of your previous questions! A reprex right from the start always helps. As a side note, please try to avoid cross-posting across sites (stackoverflow, Github, cross-validated, etc.). AFAICS there were five questions opened by you in total about the same issue in the end.

If you think something needs more discussion, you can also join our Mattermost and link to your question there.

edsantor commented 3 years ago

Hi @pat-s

Sorry for cross-posting, I'm a beginner.

Thank you very much for fixing the bug and for your valuable advice.