Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GridSearchCV in scikit-learn(sklearn): TypeError: 'KFold' object is not iterable

I'm trying to find best values of C & gamma for SVR() estimator using GridSearchCV() but I get this error

TypeError: 'KFold' object is not iterable

This the code

from sklearn.grid_search import GridSearchCV
from sklearn.model_selection import KFold
C_range = np.logspace(-2, 10, 13)
gamma_range = np.logspace(-9, 3, 13)
param_grid = dict(gamma=gamma_range, C=C_range)
cv = KFold(n_splits=5, shuffle=False, random_state=None)
grid = GridSearchCV(SVR(kernel='rbf'), param_grid=param_grid, cv=cv)
grid.fit(X, y)

print("The best parameters are %s with a score of %0.2f"
  % (grid.best_params_, grid.best_score_))
like image 431
sara_adam Avatar asked Dec 18 '25 13:12

sara_adam


1 Answers

Similar problem solved by:

Replacing:

from sklearn.grid_search import GridSearchCV

with

from sklearn.model_selection import GridSearchCV
like image 85
seralouk Avatar answered Dec 24 '25 10:12

seralouk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!