0

So I'm trying out machine learning, and following a tutorial I found online.

For some reason when I run my code numpy is giving me an error, even-though I am not importing that library. (I've been having problems with numpy)

Code:

#!/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]])

Error:

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...

Thanks

P.S. Also looking for a couple tutorial suggestions, one with machine learning and NLP would be great

9
  • 4
    Scikit-learn requires the following dependencies, specified in their documentation: Python (>= 2.7 or >= 3.3), NumPy (>= 1.8.2), SciPy (>= 0.13.3). scikit-learn.org/stable/install.html Commented Oct 17, 2017 at 14:13
  • 1
    I would say at least one of the modules you're using, imports numpy, so it is imported even if you don't write it explicitly in your code
    – Stéphane
    Commented Oct 17, 2017 at 14:14
  • @vipertherapper I have numpy 1.9.1 and SciPy 0.19.0
    – user8767766
    Commented Oct 17, 2017 at 14:17
  • It's very likely your numpy/scipy install is broken or some of these are incompatible with each other (very common here when people are using windows). This is even more likely as you are not using painless approaches like using anaconda (python distribution).
    – sascha
    Commented Oct 17, 2017 at 14:19
  • @Stéphane Never knew modules could do that in python, thanks for the info
    – user8767766
    Commented Oct 17, 2017 at 14:20

1 Answer 1

1

Numpy is a scikitlearn dependency. That means SKlearn is made on top of numpy. Creating a virtualenv is a great idea so as to understand what the real issue is.

The same code worked for me and I can tell you the prediction is "orange". :P