python - 模块未找到错误: No module named 'numpy.testing.nosetester'

标签 python numpy machine-learning importerror nose

我正在使用决策树并出现此错误。当我使用反向传播时,也出现了同样的情况。怎么解决呢?

import pandas as pd
import numpy as np
a = np.test()
f = open('E:/lgdata.csv')
data = pd.read_csv(f,index_col = 'id')

x = data.iloc[:,10:12].as_matrix().astype(int)
y = data.iloc[:,9].as_matrix().astype(int)

from sklearn.tree import DecisionTreeClassifier as DTC
dtc = DTC(criterion='entropy')
dtc.fit(x,y)
x=pd.DataFrame(x) 

from sklearn.tree import export_graphviz
with open('tree.dot','w') as f1:
    f1 = export_graphviz(dtc, feature_names = x.columns, out_file = f1)

Traceback (most recent call last):
  File "<ipython-input-40-4359c06ae1f0>", line 1, in <module>
    runfile('C:/ProgramData/Anaconda3/lib/site-packages/scipy/_lib/_numpy_compat.py', wdir='C:/ProgramData/Anaconda3/lib/site-packages/scipy/_lib')
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 710, in runfile
    execfile(filename, namespace)
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 101, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)
  File "C:/ProgramData/Anaconda3/lib/site-packages/scipy/_lib/_numpy_compat.py", line 9, in <module>
    from numpy.testing.nosetester import import_nose

ModuleNotFoundError: No module named 'numpy.testing.nosetester'

最佳答案

发生这种情况是由于 numpyscipy 之间的版本不兼容。 numpy 在其最新版本中已弃用 numpy.testing.nosetester

复制问题

pip install numpy==1.18 # > 1.18
pip install scipy<=0.19.0 # <= 0.19 

from sklearn.tree import DecisionTreeClassifier as DTC

触发错误。

修复错误

将您的 scipy 升级到更高版本。

pip install numpy==1.18
pip install scipy==1.1.0
pip install scikit-learn==0.21.3

但不限于此。通过将上述库升级到最新的稳定版,您应该能够消除此错误。

关于python - 模块未找到错误: No module named 'numpy.testing.nosetester' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59474533/

相关文章:

javascript - TFJS 模型仅预测二元分类任务的相同值

machine-learning - 地理空间机器学习的人口抽样

python - 如何有效地剥离两端带有定界字符的字符串?

python - 在 Excel VBA 或 Python 中将 xlsx 文件转换为文件夹和子文件夹内的 xls

Python 和 Numba : incorrect checksum for freed object

python - 在 pandas 数据帧 : correlate() got an unexpected keyword argument 'old behavior' 中使用最大似然估计器的自动回归 (AR) 模型

algorithm - 什么是分层 Bootstrap ?

python - 插入使用M2Crypto的代码时,_shutdown AttributeError(忽略)

python - 如何为变量值分配标签

python - 从矩阵 B 的每一行中减去矩阵 A 的每一行,无需循环