title: GridSearchCV: "TypeError: 'StratifiedKFold' object is not iterable"
body: <p>I want to perform GridSearchCV in a RandomForestClassifier, but data is not balanced, so I use StratifiedKFold:</p>
  
  <pre><code>from sklearn.model_selection import StratifiedKFold
  from sklearn.grid_search import GridSearchCV
  from sklearn.ensemble import RandomForestClassifier
  
  param_grid = {'n_estimators':[10, 30, 100, 300], "max_depth": [3, None],
            "max_features": [1, 5, 10], "min_samples_leaf": [1, 10, 25, 50], "criterion": ["gini", "entropy"]}
  
  rfc = RandomForestClassifier()
  
  clf = GridSearchCV(rfc, param_grid=param_grid, cv=StratifiedKFold()).fit(X_train, y_train)
  </code></pre>
  
  <p>But I get an error:</p>
  
  <pre><code>TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-597-b08e92c33165&gt; in &lt;module&gt;()
       9 rfc = RandomForestClassifier()
       10 
  ---&gt; 11 clf = GridSearchCV(rfc, param_grid=param_grid, cv=StratifiedKFold()).fit(X_train, y_train)
  
  c:\python34\lib\site-packages\sklearn\grid_search.py in fit(self, X, y)
      811 
      812         """
  --&gt; 813         return self._fit(X, y, ParameterGrid(self.param_grid))
  
  c:\python34\lib\site-packages\sklearn\grid_search.py in _fit(self, X, y, parameter_iterable)
      559                                     self.fit_params, return_parameters=True,
      560                                     error_score=self.error_score)
  --&gt; 561                 for parameters in parameter_iterable
      562                 for train, test in cv)
  
  c:\python34\lib\site-packages\sklearn\externals\joblib\parallel.py in __call__(self, iterable)
      756             # was dispatched. In particular this covers the edge
      757             # case of Parallel used with an exhausted iterator.
  --&gt; 758             while self.dispatch_one_batch(iterator):
      759                 self._iterating = True
      760             else:
  
  c:\python34\lib\site-packages\sklearn\externals\joblib\parallel.py in dispatch_one_batch(self, iterator)
      601 
      602         with self._lock:
  --&gt; 603             tasks = BatchedCalls(itertools.islice(iterator, batch_size))
      604             if len(tasks) == 0:
      605                 # No more tasks available in the iterator: tell caller to stop.
  
  c:\python34\lib\site-packages\sklearn\externals\joblib\parallel.py in __init__(self, iterator_slice)
      125 
      126     def __init__(self, iterator_slice):
  --&gt; 127         self.items = list(iterator_slice)
      128         self._size = len(self.items)
  
  c:\python34\lib\site-packages\sklearn\grid_search.py in &lt;genexpr&gt;(.0)
      560                                     error_score=self.error_score)
      561                 for parameters in parameter_iterable
  --&gt; 562                 for train, test in cv)
      563 
      564         # Out is a list of triplet: score, estimator, n_test_samples
  
  TypeError: 'StratifiedKFold' object is not iterable
  </code></pre>
  
  <p>When I write <code>cv=StratifiedKFold(y_train)</code> I have <code>ValueError: The number of folds must be of Integral type.</code> But when I write `cv=5, it works.</p>
  
  <p>I don't understand what is wrong with StratifiedKFold</p>