0

I'm new to scikit-learn, and currently I just want to use its train_test_split function. Below is what I typed:

from sklearn.model_selection import train_test_split

And this is the error message:

Output exceeds the size limit. Open the full output data in a text editor
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[18], line 1
----> 1 from sklearn.model_selection import train_test_split

File ~/.conda/envs/tf/lib/python3.10/site-packages/sklearn/model_selection/__init__.py:23
     20 from ._split import train_test_split
     21 from ._split import check_cv
---> 23 from ._validation import cross_val_score
     24 from ._validation import cross_val_predict
     25 from ._validation import cross_validate

File ~/.conda/envs/tf/lib/python3.10/site-packages/sklearn/model_selection/_validation.py:32
     30 from ..utils.fixes import delayed
     31 from ..utils.metaestimators import _safe_split
---> 32 from ..metrics import check_scoring
     33 from ..metrics._scorer import _check_multimetric_scoring, _MultimetricScorer
     34 from ..exceptions import FitFailedWarning

File ~/.conda/envs/tf/lib/python3.10/site-packages/sklearn/metrics/__init__.py:41
     37 from ._classification import multilabel_confusion_matrix
     39 from ._dist_metrics import DistanceMetric
---> 41 from . import cluster
     42 from .cluster import adjusted_mutual_info_score
     43 from .cluster import adjusted_rand_score
...
     19 )

File sklearn/metrics/_pairwise_distances_reduction/_base.pyx:1, in init sklearn.metrics._pairwise_distances_reduction._base()

AttributeError: module 'sklearn.metrics._dist_metrics' has no attribute 'DistanceMetric32'

I've tried to search for similar errors, and most of them are version issues. My Python is 3.10.8 and scikit-learn is 1.2.0. I tried to upgrading (1.2.0 is already the latest) and downgrading, but the error remains. In addition, the other errors I found are lack of some other attributes rather than 'DistanceMetric32'. Could anyone provides some ideas?

Aaron Wang
  • 11
  • 3
  • I created a conda env with python 3.10.8 and scikit-learn 1.2.0 and it works fine for me. Do you also have trouble importing other modules? – hash_ir Jan 04 '23 at 01:03
  • Same thing was posted a few hours ago: https://stackoverflow.com/questions/74997030/error-when-importing-sklearn-model-selection-in-scikit-learn-1-2 – Alexander L. Hayes Jan 04 '23 at 01:37
  • (1) Can you check whether you have a 32-bit copy of Python installed? (e.g. [using this](https://stackoverflow.com/questions/1405913/how-do-i-determine-if-my-python-shell-is-executing-in-32bit-or-64bit)). (2) Are you on Windows/macOS/Linux? – Alexander L. Hayes Jan 04 '23 at 01:39
  • Hi @hash_ir I currently have no trouble importing other modules. – Aaron Wang Jan 04 '23 at 17:52
  • Hi @AlexanderL.Hayes, thanks for the reply. (1) That looks like a good point! My current python is 64 bit. I didn't see a 32-bit Python installed in this env. (2) I'm on Linux. – Aaron Wang Jan 04 '23 at 19:53

0 Answers0