Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'
like image 211
Edamame Avatar asked Dec 07 '16 17:12

Edamame


People also ask

How do you resolve ImportError Cannot import name?

To resolve the ImportError: Cannot import name, modify the x.py file. Instead of importing the y module at the start of the x.py file, write at the end of the file. Now rerun, and you can see the following output. We have solved this problem by using the import module or class or function where we needed it.

How do you fix ImportError Cannot import name in Python?

The Python "ImportError: cannot import name" occurs when we have circular imports (importing members between the same files). To solve the error, move the objects to a third file and import them from a central location in other files, or nest one of the imports in a function.

Can not import name Python?

In Python "ImportError: cannot import name" error generally occurs when the imported class is not accessible, or the imported class is in a circular dependency. The following are the major reasons for the occurrence of "ImportError: cannot import name": The imported class is in a circular dependency.


2 Answers

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.

like image 94
Sayali Sonawane Avatar answered Sep 25 '22 02:09

Sayali Sonawane


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

like image 43
Jean-Claude Houbart Avatar answered Sep 24 '22 02:09

Jean-Claude Houbart