简体   繁体   中英

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()

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM