嘿,我是新来的Python,我试图用一个教程的内容,但我得到这个错误:NameError:名字“树”没有定义
NameError: name 'tree' is not defined.
目的显然是为节目根据要素的输入确定水果是苹果还是橘子。我在Win 10上使用Python 3.6和spyder编辑器。我确信这很简单,谢谢你的帮助!
# -*- 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]]))
你必须导入一些模块。它可能写在教程中。 – RafaelC