从sklearn导入DecisionTreeClassifier时出错

问题描述 投票:0回答:1

当我尝试从 sklearn.tree 导入 DecisionTreeClassifier 时,我收到以下属性错误:

AttributeError: module 'numpy' has no attribute 'float'

我的代码是:

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

输出:

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
numpy scikit-learn decision-tree
1个回答
0
投票

您收到此错误是因为您使用 np.float 作为数据类型,NumPy 不再支持该数据类型。正如错误消息所示,您应该在代码中将 np.float 替换为 float 或 np.float64

© www.soinside.com 2019 - 2024. All rights reserved.