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_))
cv
is an object in your case. You should useKFold
in order to create batches of data, and pass these batches toGridSearchCV
incv
argument.Here an example on how to create splits, using
KFold
: