嘿,我是新來的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