def ParamSelection(X, Y, nfolds):
Cs = [0.0001, 0.001, 0.01, 0.1, 1, 10, 100]
degrees = [1, 2, 3, 4, 5]
param_grid = {'C': Cs, 'degree' : degrees}
grid_search = GridSearchCV(svm.SVC(kernel = 'poly'), param_grid, cv = nfolds)
grid_search = svm.SVC(gamma='scale')
grid_search.fit(X, Y)
grid_search.best_params_
return grid_search.best_params_
ParamSelection(trainX, trainY, 10)
AttributeError: 'SVC' object has no attribute 'best_params_'
I'm getting the above error. What should I do? Can you help?
You re-assigned GridSearch
to svm
, so your GridSearch
object is not the sklearn
object. Just delete this line:
grid_search = svm.SVC(gamma='scale')
Then it should run fine. You'll get a deprecation warning, so set the gamma
parameter when instantiating SVC()
:
grid_search = GridSearchCV(svm.SVC(kernel = 'poly', gamma='scale'), param_grid, cv = nfolds)