Repository navigation
Closed
Description
Just updated sklearn:
$ python -c "import sklearn; print(sklearn, sklearn.__version__)"
(<module 'sklearn' from '/usr/local/lib/python2.7/dist-packages/sklearn/__init__.pyc'>, '0.18')
Now receiving errors for importing model_selection modules:
In [3]: from sklearn.model_selection import train_test_split
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-3-139cc3505715> in <module>()
----> 1 from sklearn.model_selection import train_test_split
/usr/local/lib/python2.7/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/python2.7/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
In [6]: from sklearn.model_selection import KFold
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-6-7748d201c9c6> in <module>()
----> 1 from sklearn.model_selection import KFold
/usr/local/lib/python2.7/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/python2.7/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
Activity
bwang482 commentedon Oct 5, 2016
from sklearn.cross_validation import train_test_splitworks but shouldn't 0.18 version be updated now?amueller commentedon Oct 5, 2016
How did you install and update scikit-learn?
If you install with conda and update with pip, there will be left-over files. I recommend uninstalling, removing the folder entirely, and reinstalling.
bwang482 commentedon Oct 5, 2016
Yes, forgot I installed with conda. Thanks, issue closed.
bwang482 commentedon Oct 5, 2016
With
from sklearn.model_selection import train_test_splitI am getting IndexError for splitting Pandas DataFrame:With the old version
train_test_split, I get no error and resulting splits are correct. Is there any differences between the old and the new that caused the IndexError? Thanks.amueller commentedon Oct 5, 2016
No, there shouldn't have been a change there.
I'm not sure that
stratifyis tested with a dataframe. What's the shape ofmeds?bwang482 commentedon Oct 5, 2016
Ah ok
medsis a list. After converting to numpy array, it now works. Thanks!Interestingly the 0.17 version
stratifyworks with list.Issue closed.
amueller commentedon Oct 5, 2016
That is strange and shouldn't happen. Can you confirm that exactly the same code worked on 0.17? Then that is a regression :(
amueller commentedon Oct 5, 2016
@raghavrv there's a check on y missing, maybe
check_Xy? Would you mind seeing if that is also the case for other stratified models or other grouped models? We should accept lists everywhere.[-]model_selecion importing "ImportError: cannot import name _safe_split"[/-][+]REGRESSION: StratifiedShuffleSplit errors on list y[/+]2 remaining items
raghavrv commentedon Oct 5, 2016
Could you give me a reproducible sample code? The following seems to work for me
bwang482 commentedon Oct 5, 2016
@raghavrv Ah I think the error is caused by the stratify list having strings. So
lesteve commentedon Oct 6, 2016
Confirmed. Here is an updated snippet that can be run under both 0.17 and 0.18:
raghavrv commentedon Oct 6, 2016
@bluemonk482 @lesteve Thanks for confirming... I've made a PR at #7593 that fixes this.
tangfucius commentedon Nov 3, 2016
@bluemonk482 I am having the error
ImportError: cannot import name _safe_splitin your first post above. I tried removing scikit-learn from conda, removing all directories named sklearn, then did a conda install again, but it still didn't work. How did you get it working? Thanks!bwang482 commentedon Nov 3, 2016
@tangfucius Make sure
which pythonpoints to the python directory you expect, OR tryfrom sklearn.cross_validation import train_test_splitinstead, which is the older versionshamrockiris commentedon Nov 3, 2016
Get error
ImportError: cannot import name _safe_splitwhile tryingfrom sklearn.model_selection import cross_val_score. Removed package and folder and reinstalled. Any thoughts how to solve this? Thank you.jnothman commentedon Nov 4, 2016
If you removed the folder, I don't know why this should happen unless
you're actually loading a different version to the one you think you are.
Check sklearn.path, for instance..
On 4 November 2016 at 08:19, Xiaowen Wang [email protected] wrote:
traethethird commentedon Nov 16, 2016
@tangfucius @shamrockiris Hopefully you're not still having the problem, but if anyone else stumbles across this, I had to uninstall/reinstall both scikit-learn and scipy to stop this error.
amueller commentedon Nov 16, 2016
@traethethird no, this is unrelated to scipy. This was not what removed the error.
Locking the issue. Please open a new issue if you have installation problems or import errors.