AttributeError:模块"numpy"没有属性"testing" [英] AttributeError: module 'numpy' has no attribute 'testing'

查看:790
本文介绍了AttributeError:模块"numpy"没有属性"testing"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上周,我能够在Python 3.7.2中运行程序.

Last week I was able to run programs in Python 3.7.2 just fine.

今天早上我进来,运行相同的程序并得到错误

This morning I come in, run the same program and get error

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

我做了全新的python 3.7.2卸载和安装

I did fresh uninstall and install of python 3.7.2

然后我做了pip3 install -U scikit-learn scipy matplotlib,运行了相同的程序,但仍然收到此错误.

Then I did pip3 install -U scikit-learn scipy matplotlib, ran same program(s) and still getting this error.

整个上午都在谷歌搜索上花了很多时间,尝试了不同的方法(当然,重新启动计算机,检查了PATH)

Spent the whole morning googling, and trying different things (and of course, rebooted machine, checked PATH)

请帮助!!!!!!

# Assigning features and label variables

# First Feature
weather=['Sunny','Sunny','Overcast','Rainy','Rainy','Rainy','Overcast','Sunny','Sunny',
'Rainy','Sunny','Overcast','Overcast','Rainy']

# Second Feature
temp=['Hot','Hot','Hot','Mild','Cool','Cool','Cool','Mild','Cool','Mild','Mild','Mild','Hot','Mild']

# Label or target varible
play=['No','No','Yes','Yes','Yes','No','Yes','No','Yes','Yes','Yes','Yes','Yes','No']


# Import LabelEncoder

from sklearn import preprocessing

# creating labelEncoder

le = preprocessing.LabelEncoder()

# converting string labels into numbers

weather_encoded = le.fit_transform(weather)

print(weather_encoded)

# converting string labels into numbers

temp_encoded = le.fit_transform(temp)

label = le.fit_transform(play)

# combining weather and temp into a single list of tuples

features = list(zip(weather_encoded,temp_encoded))


from sklearn.neighbors import KNeighborsClassifier

model = KNeighborsClassifier(n_neighbors=3)

# Train the model using the training sets

model.fit(features, label)

# Predict Output

predicted = model.predict([[0,2]]) #0:Overcast, 2:Mild

print(predicted)

追踪

e:\ML>python knn.py
Traceback (most recent call last):
  File "knn.py", line 16, in <module>
    from sklearn import preprocessing
  File "C:\Python37-32\lib\site-packages\sklearn\__init__.py", line 64, in <module>
    from .base import clone
  File "C:\Python37-32\lib\site-packages\sklearn\base.py", line 11, in <module>
    import numpy as np
  File "C:\Python37-32\lib\site-packages\numpy\__init__.py", line 187, in <module>
    from .testing import Tester
  File "C:\Python37-32\lib\site-packages\numpy\testing\__init__.py", line 12, in <module>
    from ._private.utils import *
  File "C:\Python37-32\lib\site-packages\numpy\testing\_private\utils.py", line 16, in <module>
    from tempfile import mkdtemp, mkstemp
  File "C:\Python37-32\lib\tempfile.py", line 45, in <module>
    from random import Random as _Random
  File "e:\ML\random.py", line 4, in <module>
    from sklearn import datasets
  File "C:\Python37-32\lib\site-packages\sklearn\datasets\__init__.py", line 6, in <module>
    from .base import load_breast_cancer
  File "C:\Python37-32\lib\site-packages\sklearn\datasets\base.py", line 20, in <module>
    from ..utils import Bunch
  File "C:\Python37-32\lib\site-packages\sklearn\utils\__init__.py", line 10, in <module>
    from scipy.sparse import issparse
  File "C:\Python37-32\lib\site-packages\scipy\sparse\__init__.py", line 230, in <module>
    from .base import *
  File "C:\Python37-32\lib\site-packages\scipy\sparse\base.py", line 9, in <module>
    from scipy._lib._numpy_compat import broadcast_to
  File "C:\Python37-32\lib\site-packages\scipy\_lib\_numpy_compat.py", line 16, in <module>
    _assert_warns = np.testing.assert_warns
AttributeError: module 'numpy' has no attribute 'testing'

推荐答案

运行其他导入代码,例如:

run an additional import code, example:

import np.testing as npt
npt.assert_array_almost_equal(answer1, answer2 )

这篇关于AttributeError:模块"numpy"没有属性"testing"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆