0

When I try to import a DecisionTreeClassifier from sklearn.tree I receive the following attribute error: AttributeError: module 'numpy' has no attribute 'float'

My code is:

import sklearn
print(sklearn.__version__)
from sklearn.tree import DecisionTreeClassifier

Output:

0.23.2

AttributeError: module 'numpy' has no attribute 'float'.
`np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
2
  • 4
    Sklearn 0.23.2 is roughly 4 years old. Have you tried upgrading to the latest version? Commented Feb 17, 2024 at 19:29
  • and if for some reason you must use this older sklearn, you probably need to also install an older numpy Commented Feb 18, 2024 at 1:29

1 Answer 1

0

You are getting this error because you are using np.float as a data type, which is no longer supported by NumPy. As the error message suggests, you should replace np.float with float or np.float64 in your code.

import numpy as np
a = np.array([1.2, 3.4, 5.6], dtype=float) # use float instead of 
np.float

Please try this and five an update.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.