Hey I'm new to Python and I am trying to follow along with a tutorial but I get this error:
NameError: name 'tree' is not defined.
The objective is obviously for the program to determine whether the fruit is an apple or orange based on the input of features. I'm using Python 3.6 with the spyder editor on Win 10. I'm sure it's something simple, thanks for any help!
# -*- 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]]))
Add this to the top of your code:
from sklearn import tree
This is assuming that you are studying machine learning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With