def gridsearch(Classifier, documents=[], folds=10, **kwargs):
 def product(*args):
  p = [[]]
  for iterable in args:
   p = [(x + [y]) for x in p for y in iterable]
  for p in p:
   (yield tuple(p))
 s = []
 p = []
 for (k, v) in kwargs.items():
  p.append([(k, v) for v in v])
 for p in product(*p):
  p = dict(p)
  s.append((K_fold_cross_validation(Classifier, documents, folds, **p), p))
 return sorted(s, reverse=True)

def gridsearch ( Classifier , documents = [ ] , folds = 10 , ** kwargs ) : def product ( * args ) : p = [ [ ] ] for iterable in args : p = [ ( x + [ y ] ) for x in p for y in iterable ] for p in p : ( yield tuple ( p ) ) s = [ ] p = [ ] for ( k , v ) in kwargs . items ( ) : p . append ( [ ( k , v ) for v in v ] ) for p in product ( * p ) : p = dict ( p ) s . append ( ( K_fold_cross_validation ( Classifier , documents , folds , ** p ) , p ) ) return sorted ( s , reverse = True )
returns the test results for every combination of optional parameters .