我最近使用pip安装了Scipy、Numpy和Scikit-learn,但当我运行下面的程序时:
from sklearn import tree
features = [[140, 1], [130, 1], [150, 1], [170, 1]] #input
labels = [0, 0, 1, 1] #output
clf = tree.DecisionTreeClassifier()
clf = clf.fit(features, labels) #fit = find patterns in data
print (clf.predict([[160, 0]]))
Shell会打印出这个错误信息
Traceback (most recent call last):
File "C:/Machine Learning/sklearn.py", line 1, in <module>
from sklearn import tree
File "C:/Machine Learning\sklearn.py", line 1, in <module>
from sklearn import tree
ImportError: cannot import name 'tree'
有人知道如何解决这个问题吗?我已经尝试卸载和重新安装它,但是我仍然遇到了相同的错误。非常感谢提前!
sklearn.py
。请停止这样做。 - user2357112sklearn.pyc
文件,重新启动 Python,然后再尝试。 - user2357112