嘿,我是Python的新手,正在尝试跟随教程,但是出现了以下错误:
NameError: name 'tree' is not defined.
显然,目标是根据输入的特征确定水果是苹果还是橙子。我在Win 10上使用带有Spyder编辑器的Python 3.6。我相信这是一些简单的问题,感谢任何帮助!
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
# features = [[140, "smooth"], [130, "smooth"], [150, "bumpy"], [170, "bumpy"]]
# labels = ["apple", "apple", "orange", "orange"]
features = [[140, 1], [130, 1], [150, 0], [170, 0]]
labels = [0, 0, 1, 1]
# We build a "Decision Tree" yes/no -> yes/no
# clf means classifier
clf = tree.DecisionTreeClassifier()
# Think of "fit" as "find patters in data"
clf = clf.fit(features, labels)
print (clf.predict([[160, 0]]))