Repository: mne-tools/mne-python

Issue:
Sklearn warnings for cov
I'm running latest `sklearn` and I get this when doing `mne.compute_covariance`:

```
/home/larsoner/.local/lib/python2.7/site-packages/sklearn/cross_validation.py:42: DeprecationWarning: This module has been deprecated in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.
  "This module will be removed in 0.20.", DeprecationWarning)
/home/larsoner/.local/lib/python2.7/site-packages/sklearn/grid_search.py:43: DeprecationWarning: This module has been deprecated in favor of the model_selection module into which all the refactored classes and functions are moved. This module will be removed in 0.20.
  DeprecationWarning)
```

@agramfort @dengemann any time to look into how to fix this before 0.11 release (in the next week probably), or should we push to 0.12?



Discussion:
git grep cross_validation

then rename cross_validation to model_selection

and make sure tests pass and updated examples also

however we should support both versions for some time but just in the code
(not in examples)

Not that simple unfortunately, just spent half an hour trying to fix `time_gen.py` but it's not trivial. There are API changes from `cross_validation` to `model_selection` in terms of how iteration is done, and when different parameters are passed. So @dengemann or @kingjr (most recent authors in that vicinity) will probably have to take a look. Moving to 0.12.

do you have a WIP PR I could take over during we?

No, I only had one or two good lines and a bunch of not-working junk after that so I `reset --hard`. Your idea was a good start, though. You can run `mne/tests/test_cov.py` and `mne/decoding/tests` to see the warnings.


Resolving patch:
diff --git a/mne/cov.py b/mne/cov.py
--- a/mne/cov.py
+++ b/mne/cov.py
@@ -785,7 +785,10 @@ def _compute_covariance_auto(data, method, info, method_params, cv,
                              scalings, n_jobs, stop_early, picks_list,
                              verbose):
     """docstring for _compute_covariance_auto."""
-    from sklearn.grid_search import GridSearchCV
+    try:
+        from sklearn.model_selection import GridSearchCV
+    except: # XXX support sklearn < 0.18
+        from sklearn.grid_search import GridSearchCV
     from sklearn.covariance import (LedoitWolf, ShrunkCovariance,
                                     EmpiricalCovariance)
 
@@ -911,7 +914,11 @@ def _gaussian_loglik_scorer(est, X, y=None):
 
 def _cross_val(data, est, cv, n_jobs):
     """Helper to compute cross validation."""
-    from sklearn.cross_validation import cross_val_score
+    try:
+        from sklearn.model_selection import cross_val_score
+    except ImportError:
+        # XXX support sklearn < 0.18
+        from sklearn.cross_validation import cross_val_score
     return np.mean(cross_val_score(est, data, cv=cv, n_jobs=n_jobs,
                                    scoring=_gaussian_loglik_scorer))
 
diff --git a/mne/decoding/ems.py b/mne/decoding/ems.py
--- a/mne/decoding/ems.py
+++ b/mne/decoding/ems.py
@@ -92,11 +92,22 @@ def compute_ems(epochs, conditions=None, picks=None, n_jobs=1, verbose=None):
                 this_picks = pick_types(info, meg=ch_type, eeg=False)
             data[:, this_picks] /= np.std(data[:, this_picks])
 
-    from sklearn.cross_validation import LeaveOneOut
+    try:
+        from sklearn.model_selection import LeaveOneOut
+    except:  # XXX support sklearn < 0.18
+        from sklearn.cross_validation import LeaveOneOut
+
+    def _iter_cv(n):  # XXX support sklearn < 0.18
+        if hasattr(LeaveOneOut, 'split'):
+            cv = LeaveOneOut()
+            return cv.split(np.zeros((n, 1)))
+        else:
+            cv = LeaveOneOut(len(data))
+            return cv
 
     parallel, p_func, _ = parallel_func(_run_ems, n_jobs=n_jobs)
     out = parallel(p_func(_ems_diff, data, cond_idx, train, test)
-                   for train, test in LeaveOneOut(len(data)))
+                   for train, test in _iter_cv(len(data)))
 
     surrogate_trials, spatial_filter = zip(*out)
     surrogate_trials = np.array(surrogate_trials)


Test patch: