Edamame
Edamame

Reputation: 25366

ImportError: cannot import name '_safe_split'

I got the following errors when I tried to use the train_test_split function. Then I tried to install scipy, but it didn't help. Does anyone know which I might be missing from the error below? Thanks!


ImportError                               Traceback (most recent call last)
<ipython-input-53-57bf27feca45> in <module>()
      1 import numpy as np
----> 2 from sklearn.model_selection import train_test_split
      3 
      4 X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.33, random_state=42)

/usr/local/lib/python3.4/dist-packages/sklearn/model_selection/__init__.py in <module>()
     15 from ._split import check_cv
     16 
---> 17 from ._validation import cross_val_score
     18 from ._validation import cross_val_predict
     19 from ._validation import learning_curve

/usr/local/lib/python3.4/dist-packages/sklearn/model_selection/_validation.py in <module>()
     25 from ..utils.fixes import astype
     26 from ..utils.validation import _is_arraylike, _num_samples
---> 27 from ..utils.metaestimators import _safe_split
     28 from ..externals.joblib import Parallel, delayed, logger
     29 from ..metrics.scorer import check_scoring

ImportError: cannot import name '_safe_split'

Upvotes: 8

Views: 7717

Answers (4)

wastetime909
wastetime909

Reputation: 1342

This normally happens after you update certain packages in Anaconda. Please first confirm whether you have Anaconda installed as well. Try this to help you import train_test_split:

from sklearn.cross_validation import train_test_split

If this works, then try uninstall it by using both conda and pip then install it with pip, see if you can import it by using the regular way. I once accidentally installed both "scikit-learn" and "sklearn" packages on python and this might lead to the problem as well.

Upvotes: 0

Sayali Sonawane
Sayali Sonawane

Reputation: 12599

Strange thing is: I got this error after upgrading to scikit version to 0.18.1

I restarted python console and it solved my problem.

Upvotes: 5

Nodar Okroshiashvili
Nodar Okroshiashvili

Reputation: 11

I had same problem and solved by importing "Scipy", "Numpy", "Pandas", "Matplotlib" and initially I updated "Scikit-learn".

Upvotes: 1

Jean-Claude Houbart
Jean-Claude Houbart

Reputation: 31

I solved this same problem by updating the version of scikit to 0.18.1

Upvotes: 3

Related Questions