TypeError: The "ShuffleSplit" object is not iterable

I use ShuffleSplit to shuffle the data, but I found that there is an error

TypeError                                 Traceback (most recent call last)
<ipython-input-36-192f7c286a58> in <module>()
      1 # Fit the training data to the model using grid search
----> 2 reg = fit_model(X_train, y_train)
      3 
      4 # Produce the value for 'max_depth'
      5 print "Parameter 'max_depth' is {} for the optimal model.".format(reg.get_params()['max_depth'])

<ipython-input-34-18b2799e585c> in fit_model(X, y)
     32 
     33     # Fit the grid search object to the data to compute the optimal model
---> 34     grid = grid.fit(X, y)
     35 
     36     # Return the optimal model after fitting the data

/Library/Python/2.7/site-packages/sklearn/grid_search.pyc in fit(self, X, y)
    827 
    828         """
--> 829         return self._fit(X, y, ParameterGrid(self.param_grid))
    830 
    831 

/Library/Python/2.7/site-packages/sklearn/grid_search.pyc in _fit(self, X, y, parameter_iterable)
    571                                     self.fit_params, return_parameters=True,
    572                                     error_score=self.error_score)
--> 573                 for parameters in parameter_iterable
    574                 for train, test in cv)
    575 

/Library/Python/2.7/site-packages/sklearn/externals/joblib/parallel.pyc in __call__(self, iterable)
    756             # was dispatched. In particular this covers the edge
    757             # case of Parallel used with an exhausted iterator.
--> 758             while self.dispatch_one_batch(iterator):
    759                 self._iterating = True
    760             else:

/Library/Python/2.7/site-packages/sklearn/externals/joblib/parallel.pyc in dispatch_one_batch(self, iterator)
    601 
    602         with self._lock:
--> 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.

/Library/Python/2.7/site-packages/sklearn/externals/joblib/parallel.pyc in __init__(self, iterator_slice)
    125 
    126     def __init__(self, iterator_slice):
--> 127         self.items = list(iterator_slice)
    128         self._size = len(self.items)
    129 

/Library/Python/2.7/site-packages/sklearn/grid_search.pyc in <genexpr>((parameters,))
    572                                     error_score=self.error_score)
    573                 for parameters in parameter_iterable
--> 574                 for train, test in cv)
    575 
    576         # Out is a list of triplet: score, estimator, n_test_samples

TypeError: 'ShuffleSplit' object is not iterable

And he showed a warning

/Library/Python/2.7/site-packages/sklearn/cross_validation.py:44: DeprecationWarning: 0.18 model_selection, . , CV . 0.20.    " 0.20"., DeprecationWarning) /Library/Python/ 2.7/site-packages/sklearn/grid_search.py:43: DeprecationWarning: 0.18 model_selection, . 0.20.   DeprecationWarning)

from sklearn.metrics import make_scorer
from sklearn.tree import DecisionTreeRegressor
from sklearn.grid_search import GridSearchCV

from sklearn.model_selection import GridSearchCV
from sklearn.tree import DecisionTreeRegressor
from sklearn.metrics import make_scorer  

scikit-learn - 0.18.1.

?

+1
1

GridSearchCV grid_search, :

from sklearn.grid_search import GridSearchCV

, :

0.18 model_selection, . , CV . 0.20.

, .

: - grid_search. model_selection.

+7

Source: https://habr.com/ru/post/1669714/


All Articles