How to avoid "WARNING: reaching max number of iterations" while using tune.svm

200 views Asked by At

I have a dataset of 6216 observations and 17 predictors. I want to build a SVM for regression analysis. My goal is to tune the hyperparameters, in order to improve the model as possible. I'm doing it for a didactic purpose so I have to show the best solution with a linear, a radial basis function, a polynomial and sigmoid kernel, and after that define the best. Since the function tune.svm uses a 10-fold cross validation as default, I decided to set instead a 5-fold cross validation, to reduce the complexity.

The code below is the one I'm trying to use in case of a linear kernel, but I keep getting the warning.

svm.tuning <- tune.svm(x = x_scaled[,names(x_scaled)!="sal_perc"],y = x_scaled[,"sal_perc"],
                            cost = 10^(-4:2), tunecontrol=tune.control(cross = 5), kernel="linear")

If I run it, it takes about 10/15 minutes to execute (with the 10-fold about an hour). I don't want to imagine how long will be with the other kernels, where I should tune even the gamma parameter. While running it, I keep seeing this:

> svm.tuning <- tune.svm(x = x_scaled[,names(x_scaled)!="sal_perc"],y = x_scaled[,"sal_perc"],
+                             cost = 10^(-4:2), tunecontrol=tune.control(cross = 5), kernel="linear")

WARNING: reaching max number of iterations

WARNING: reaching max number of iterations

WARNING: reaching max number of iterations

WARNING: reaching max number of iterations

WARNING: reaching max number of iterations

WARNING: reaching max number of iterations

WARNING: reaching max number of iterations

WARNING: reaching max number of iterations

WARNING: reaching max number of iterations

I've found this guy has the same problem, but the solution given is with a package which seems doesn't exist anymore (Weird error message when tuning svm with polynomial kernel: "WARNING: reaching max number of iterations"). I've also checked if the problem could be from my data, but they are normalized and balanced, as explained here (https://stats.stackexchange.com/questions/37669/libsvm-reaching-max-number-of-iterations-warning-and-cross-validation). Is it possible to increase the max number of iterations? Because the package e1071, which includes tune.svm, has this number locked. However, I get the warning even if assigning only two values at the cost hyperparameter.

1

There are 1 answers

0
ARaphs On BEST ANSWER

I update the question with this answer because I found a faster method which prevent every warning. It is simply made with train and trainControl functions. Actually, to get a faster tuning it's necessary to choose a random search of the hyperparameters, instead of a grid. By writing this two lines it's so easy tuning svm hyperparameter.

tune.ctrl <- trainControl(method = "cv",number = 5,search = "random")
svm.tunlin_game <- train(sal_perc ~., data=x_scaled, method="svmLinear2", metric="RMSE",tunecontrol=tune.ctrl)

In my case, this solution takes about 2 minutes, instead the one in the question which takes about 10/15 minutes. The only negative side is that I didn't find the sygmoid kernel method in the classic train function.