def grid_search(X_train,y,clfs): print "grid searching" for name,clf in clfs.iteritems(): print name param_grid=clfs[name]['grid'] param_list = list(ParameterGrid(param_grid)) for i in range(0,len(param_list)): reg=clfs[name]['est'].set_params(**param_list[i]) cv=cv_score1(reg,X_train,y) print [cv.mean(),name,param_list[i]]