Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am using GridSearchCV and fit is giving me a TypeError: get_params() missing 1 required positional argument: 'self'

I am using grid search for getting the best fit

k=['rbf', 'linear','poly','sigmoid']
c= [1,5,10,20,30,50,80,100]
g=[1e-7,1e-6,1e-5,1e-4,1e-2,0.0001]

param_grid=dict(kernel=k, C=c, gamma=g)
print (param_grid)
grid = GridSearchCV(SVC, param_grid,scoring='accuracy')
grid.fit(X_t_train, y_t_train)  

print()
print("Grid scores on development set:")
print()  
print (grid.grid_scores_)
print("Best parameters set found on development set:")
print()
print(grid.best_params_)
print("Grid best score:")
print()
print (grid.best_score_)

I am getting a TypeError: get_params() missing 1 required positional argument: 'self' in grid.fit()

like image 410
Prem Anand Avatar asked Mar 07 '23 21:03

Prem Anand


1 Answers

This error appears because estimator must be initialied with object and not a class. You need to do either this:

grid = GridSearchCV(SVC(), param_grid, scoring='accuracy')

Or something like this:

clf = SVC()
grid = GridSearchCV(clf, param_grid, scoring='accuracy')
like image 198
Andrey Lukyanenko Avatar answered Apr 27 '23 19:04

Andrey Lukyanenko