未导入时Numpy给出错误。

时间:2017-10-17 14:11:21

标签: python python-2.7 numpy machine-learning scikit-learn

所以我正在尝试机器学习,并按照我在网上找到的教程。

由于某些原因,当我运行我的代码时,numpy会给我一个错误,即使我没有导入该库。 (我一直遇到numpy问题)

代码:

#!/usr/bin/env python
from sklearn import tree

#1 = smooth       0 = bumpy
features = [[140, 1], [130, 1], [150, 0], [170, 0]] #input
labels = ["apple", "apple", "orange", "orange"] #desired output
#0 = apple         1 = orange

clf = tree.DecisionTreeClassifier()
clf = clf.fit(features, labels)
print clf.predict([[160, 0]])

错误:

C:\Windows\system32\cmd.exe /c (python ^<C:\Users\me\AppData\Local\Temp\22\V
Ii532A.tmp)
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "E:\Python27\lib\site-packages\sklearn\__init__.py", line 134, in <module
>
    from .base import clone
  File "E:\Python27\lib\site-packages\sklearn\base.py", line 9, in <module>
    import numpy as np
  File "E:\Python27\lib\site-packages\numpy\__init__.py", line 142, in <module>
    from . import add_newdocs
  File "E:\Python27\lib\site-packages\numpy\add_newdocs.py", line 13, in <module
>
    from numpy.lib import add_newdoc
  File "E:\Python27\lib\site-packages\numpy\lib\__init__.py", line 8, in <module
>
    from .type_check import *
  File "E:\Python27\lib\site-packages\numpy\lib\type_check.py", line 11, in <mod
ule>
    import numpy.core.numeric as _nx
  File "E:\Python27\lib\site-packages\numpy\core\__init__.py", line 21, in <modu
le>
    from . import function_base
  File "E:\Python27\lib\site-packages\numpy\core\function_base.py", line 7, in <
module>
    from .numeric import (result_type, NaN, shares_memory, MAY_SHARE_BOUNDS,
ImportError: cannot import name shares_memory
shell returned 1
Hit any key to close this window...

由于

P.S。 同时寻找一些教程建议,一个机器学习和NLP将是伟大的

1 个答案:

答案 0 :(得分:1)

Numpy是一种scikitlearn依赖。这意味着SKlearn是在numpy之上制作的。 创建virtualenv是一个好主意,以便了解真正的问题是什么。

相同的代码对我有用,我可以告诉你预测是&#34;橙&#34;。 :P