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'
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.
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.
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.
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.
I solved this same problem by updating the version of scikit to 0.18.1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With