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

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?

Related

hello everyone, Iam new to programming, I am using jupyter notebook using anaconda, here i found some problem with the importing of libraries

# lstm model
import tensorflow as tf
from numpy import mean
from numpy import std
from numpy import dstack
from pandas import read_csv
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.layers import Flatten
from tensorflow.keras.layers import Dropout
from tensorflow.keras.layers import LSTM
from tensorflow.keras.utils import to_categorical
from matplotlib import pyplot
When i run this cell iam getting the below error, I am using jupyter notebook using anaconda, using anaconda every packages will be installed related to python but in this it is showing regarding tensorflow problem while the importing libraries, I am using latest version of python 3.9,would anyone help to resolve the issue
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_10616/748904884.py in <module>
1 # lstm model
----> 2 import tensorflow as tf
3 from numpy import mean
4 from numpy import std
5 from numpy import dstack
~\AppData\Roaming\Python\Python39\site-packages\tensorflow\__init__.py in <module>
39 import sys as _sys
40
---> 41 from tensorflow.python.tools import module_util as _module_util
42 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader
43
~\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\__init__.py in <module>
44
45 # Bring in subpackages.
---> 46 from tensorflow.python import data
47 from tensorflow.python import distribute
48 # from tensorflow.python import keras
~\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\data\__init__.py in <module>
23
24 # pylint: disable=unused-import
---> 25 from tensorflow.python.data import experimental
26 from tensorflow.python.data.ops.dataset_ops import AUTOTUNE
27 from tensorflow.python.data.ops.dataset_ops import Dataset
~\AppData\Roaming\Python\Python39\sitepackages\tensorflow\python\data\experimental\__init__.py
in <module>
96
97 # pylint: disable=unused-import
---> 98 from tensorflow.python.data.experimental import service
99 from tensorflow.python.data.experimental.ops.batching import dense_to_ragged_batch
100 from tensorflow.python.data.experimental.ops.batching import dense_to_sparse_batch
~\AppData\Roaming\Python\Python39\site-
packages\tensorflow\python\data\experimental\service\__init__.py in <module>
372 from __future__ import print_function
373
--> 374 from tensorflow.python.data.experimental.ops.data_service_ops import distribute
375 from tensorflow.python.data.experimental.ops.data_service_ops import from_dataset_id
376 from tensorflow.python.data.experimental.ops.data_service_ops import register_dataset
~\anaconda3\envs\mygpu\lib\site-
packages\tensorflow\python\data\experimental\ops\data_service_ops.py in <module>
23
24 from tensorflow.python import tf2
---> 25 from tensorflow.python.data.experimental.ops import compression_ops
26 from tensorflow.python.data.experimental.ops.distribute_options import AutoShardPolicy
27 from tensorflow.python.data.experimental.ops.distribute_options import
ExternalStatePolicy
~\anaconda3\envs\mygpu\lib\site-
packages\tensorflow\python\data\experimental\ops\compression_ops.py in <module>
18 from __future__ import print_function
19
---> 20 from tensorflow.python.data.util import structure
21 from tensorflow.python.ops import gen_experimental_dataset_ops as ged_ops
22
~\anaconda3\envs\mygpu\lib\site-packages\tensorflow\python\data\util\structure.py in <module>
24 import wrapt
25
---> 26 from tensorflow.python.data.util import nest
27 from tensorflow.python.framework import composite_tensor
28 from tensorflow.python.framework import ops
~\anaconda3\envs\mygpu\lib\site-packages\tensorflow\python\data\util\nest.py in <module>
38 import six as _six
39
---> 40 from tensorflow.python.framework import sparse_tensor as _sparse_tensor
41 from tensorflow.python.util import _pywrap_utils
42 from tensorflow.python.util import nest
~\anaconda3\envs\mygpu\lib\site-packages\tensorflow\python\framework\sparse_tensor.py in
<module>
26 from tensorflow.python import tf2
27 from tensorflow.python.framework import composite_tensor
---> 28 from tensorflow.python.framework import constant_op
29 from tensorflow.python.framework import dtypes
30 from tensorflow.python.framework import ops
~\anaconda3\envs\mygpu\lib\site-packages\tensorflow\python\framework\constant_op.py in
<module>
27 from tensorflow.core.framework import types_pb2
28 from tensorflow.python.eager import context
---> 29 from tensorflow.python.eager import execute
30 from tensorflow.python.framework import dtypes
31 from tensorflow.python.framework import op_callbacks
~\anaconda3\envs\mygpu\lib\site-packages\tensorflow\python\eager\execute.py in <module>
25 from tensorflow.python import pywrap_tfe
26 from tensorflow.python.eager import core
---> 27 from tensorflow.python.framework import dtypes
28 from tensorflow.python.framework import ops
29 from tensorflow.python.framework import tensor_shape
~\anaconda3\envs\mygpu\lib\site-packages\tensorflow\python\framework\dtypes.py in <module>
30 from tensorflow.python.util.tf_export import tf_export
31
---> 32 _np_bfloat16 = _pywrap_bfloat16.TF_bfloat16_type()
33
34
TypeError: Unable to convert function return value to a Python type! The signature was
() -> handle
First try to install each package one by one and you will be able to use it at once.
I was having this issue on m1 macbook, turns out my tensorflow dependency was not in sync with my tensorflow-macos package. This would be a good place to check, In this page the version they give is 2.6.0 but the newest version for tf-macos when running this command python -m pip install tensorflow-macos gives 2.8.0 thus the error. If you just updated your tensorflow version this could very well be there case, go through you tensorflow dependencies and see if there's a mix up.
If that doesn't solve it, then yeah install tokenizer first then transformer, see if that solves the issue

AttributeError: type object 'sklearn.tree._criterion.array' has no attribute '__reduce_cython__'

I want to import
from sklearn.tree import DecisionTreeRegressor in jupyter.
but when I run just the line contains above import, I got this error.
<ipython-input-16-28b3e81cd98d> in <module>
----> 1 from sklearn.tree import DecisionTreeRegressor
~/.local/lib/python3.6/site-packages/sklearn/tree/__init__.py in <module>
4 """
5
----> 6 from ._classes import BaseDecisionTree
7 from ._classes import DecisionTreeClassifier
8 from ._classes import DecisionTreeRegressor
~/.local/lib/python3.6/site-packages/sklearn/tree/_classes.py in <module>
38 from ..utils.validation import check_is_fitted
39
---> 40 from ._criterion import Criterion
41 from ._splitter import Splitter
42 from ._tree import DepthFirstTreeBuilder
~/.local/lib/python3.6/site-packages/sklearn/tree/_criterion.cpython-36m-x86_64-linux-gnu.so in init sklearn.tree._criterion()
AttributeError: type object 'sklearn.tree._criterion.array' has no attribute '__reduce_cython__'
I tried to install scipy and update scikit-learn by conda but it didn't solved.
Try to update Cython :
pip install cython

Module tesnorflow has no attribute "UninitializedVariable" tensorflow hub error

I have tensorflow version "1.14.0" and pip3 is also updated. But when I do:-
import tensorflow as tf
I get this error:
AttributeError: module 'tensorflow.python.ops.resource_variable_ops' has no attribute 'UninitializedVariable'
Tensorflow hub has version 0.5.0. Some answers on stack overflow have suggested that tensorflow version should be greater than 1.7.0 and mine is greater and still I don't know why is hub not being imported. The complete traceback of error is:-
AttributeError Traceback (most recent call last)
<ipython-input-24-d70b4e927300> in <module>
1 from sklearn.model_selection import train_test_split
2 import tensorflow as tf
----> 3 import tensorflow_hub as hub
~/.local/lib/python3.6/site-packages/tensorflow_hub/__init__.py in <module>
27 # error message is thrown instead of an obscure error of missing
28 # symbols at executing the imports.
---> 29 from tensorflow_hub.estimator import LatestModuleExporter
30 from tensorflow_hub.estimator import register_module_for_export
31 from tensorflow_hub.feature_column import image_embedding_column
~/.local/lib/python3.6/site-packages/tensorflow_hub/estimator.py in <module>
23 from absl import logging
24 import tensorflow as tf
---> 25 from tensorflow_hub import tf_utils
26 from tensorflow_hub import tf_v1
27
~/.local/lib/python3.6/site-packages/tensorflow_hub/tf_utils.py in <module>
31 # depending on TensorFlow internal implementation details.
32 # pylint: disable=g-direct-tensorflow-import
---> 33 from tensorflow.python.feature_column import feature_column_v2
34 # pylint: enable=g-direct-tensorflow-import
35
~/.local/lib/python3.6/site-packages/tensorflow/python/feature_column/feature_column_v2.py in <module>
164 from tensorflow.python.platform import tf_logging as logging
165 from tensorflow.python.training import checkpoint_utils
--> 166 from tensorflow.python.training.tracking import tracking
167 from tensorflow.python.util import deprecation
168 from tensorflow.python.util import nest
~/.local/lib/python3.6/site-packages/tensorflow/python/training/tracking/tracking.py in <module>
21 import weakref
22
---> 23 from tensorflow.python.eager import def_function
24 from tensorflow.python.eager import function as defun
25 from tensorflow.python.framework import dtypes
~/.local/lib/python3.6/site-packages/tensorflow/python/eager/def_function.py in <module>
38
39
---> 40 class UnliftedInitializerVariable(resource_variable_ops.UninitializedVariable):
41 """Variable which does not lift its initializer out of function context.
42
AttributeError: module 'tensorflow.python.ops.resource_variable_ops' has no attribute 'UninitializedVariable'
I have tried uninstalling tf completely and then installing again, reinstalling tf hub and updating pip so far. Any help will be very much appreciated!

ModuleNotFoundError: No module named 'sklearn.tree._criterion'

I am able to import sklearn on jupyter notebook. however, when I am trying to import "DecisionTreeClassifier", I am facing "ModuleNotFoundError: No module named 'sklearn.tree._criterion'" error
Code:
from sklearn.tree import DecisionTreeClassifier
Error message:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-462-f146622b3284> in <module>()
----> 1 from sklearn.tree import DecisionTreeClassifier
~\Anaconda3\lib\site-packages\sklearn\tree\__init__.py in <module>()
4 """
5
----> 6 from .tree import DecisionTreeClassifier
7 from .tree import DecisionTreeRegressor
8 from .tree import ExtraTreeClassifier
~\Anaconda3\lib\site-packages\sklearn\tree\tree.py in <module>()
38 from ..utils.validation import check_is_fitted
39
---> 40 from ._criterion import Criterion
41 from ._splitter import Splitter
42 from ._tree import DepthFirstTreeBuilder
ModuleNotFoundError: No module named 'sklearn.tree._criterion'
Any help greatly appreciated!

Import in jupyter notebook fails and command line succeeds

The following code imports absolutely fine at the command line:
# Modelling Algorithms
from sklearn.tree import DecisionTreeClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.neighbors import KNeighborsClassifier
However in Jupyter I get the following error:
ImportError Traceback (most recent call last)
<ipython-input-7-f56620e65a88> in <module>()
8
9 # Modelling Algorithms
---> 10 from sklearn.tree import DecisionTreeClassifier
11 from sklearn.linear_model import LogisticRegression
12 from sklearn.neighbors import KNeighborsClassifier
/home/username/.virtualenvs/jupyter/local/lib/python2.7/site-packages/sklearn/__init__.py in <module>()
54 # process, as it may not be compiled yet
55 else:
---> 56 from . import __check_build
57 from .base import clone
58 __check_build # avoid flakes unused variable error
ImportError: cannot import name __check_build
The output of sys.executable is the same.
I would love to fix this.

Categories