Muhammad Shahzad
Muhammad Shahzad

Reputation: 381

Optimizing SVR() parameters using GridSearchCv

I want to tune the parameters of the "SVR()" regression function. It starts processing and doesn't stop, I am unable to figure out the problem. I am predicting a parameter using the SVM regression function SVR(). The results are not good with default values in Python.so I want to try tunning it with "GridSearchCv". The last part "grids.fit(Xtrain,ytrain)" start running without giving any error and doesn't stop. SVR() tunning using GridSearch Code:

from sklearn.model_selection import GridSearchCV.

param = {'kernel' : ('linear', 'poly', 'rbf', 'sigmoid'),'C' : [1,5,10],'degree' : [3,8],'coef0' : [0.01,10,0.5],'gamma' : ('auto','scale')},

modelsvr = SVR(),

grids = GridSearchCV(modelsvr,param,cv=5)

grids.fit(Xtrain,ytrain)

It Continues to process without stopping.

Upvotes: 5

Views: 19670

Answers (3)

Samson
Samson

Reputation: 1

i have this same issue actually and i have been running it for 700min but still no result yet. had to restart kernel and switched to google colab maybe my system local machine wasnt working fine but now its running and not stopping either.

svm_param_grid = {
    'kernel': ['linear', 'poly'],
    'C': [0.1, 1],
    'epsilon': [0.1],
    'gamma': ['scale']
}

svm_model = SVR()

svm_grid_search = GridSearchCV(svm_model, svm_param_grid, cv=3)
svm_grid_search.fit(x_train, y_train)

so i think it will take a lot of time to run. i have 5k rows of data.

Upvotes: -1

Florian Beyer
Florian Beyer

Reputation: 45

Maybe you should add two more options to your GridSearch (n_jobs and verbose) :

grid_search = GridSearchCV(estimator = svr_gs, param_grid = param, 
                      cv = 3, n_jobs = -1, verbose = 2)

verbose means that you see some output about the progress of your process.

n_jobs is the numebr of used cores (-1 means all cores/threads you have available)

Upvotes: 3

KARTHIKEYAN MOHANRAJ
KARTHIKEYAN MOHANRAJ

Reputation: 56

Yes, you are right. I have come across the same scenario, when I try to run GridsearchCV for SVR(). The possible reasons are, 1) Your Processor memory(RAM) must be less, 2) The train data sample size is more, equal chance of consuming more time to run Gridsearch since your processor is low memory, so without any error the Job running time will be more.

For your info: I have run Gridsearch with train sample size of 30K using 16GB RAM memory space, it elapsed 210mins to finish the run. So, here patience is must.

Happy Analyzing !!

Upvotes: 4

Related Questions