Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NameError: name 'tree' is not defined

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]]))
like image 574
JacobElliott Avatar asked Mar 23 '17 14:03

JacobElliott


1 Answers

Add this to the top of your code:

from sklearn import tree

This is assuming that you are studying machine learning.

like image 101
BoobyTrap Avatar answered Oct 14 '22 22:10

BoobyTrap