Where is the "tree"? in the first line of code
When I ran this line of code at the beginning of this lesson:
clf = tree.DecisionTreeClassifier(random_state=365)
I got an error saying it can't find "tree". What is going on?
Thanks.
1 answers ( 0 marked as helpful)
Hi,
This just depends on your imports.
You have 2 options:
from sklearn import tree
clf = tree.DecisionTreeClassifier(random_state=365)
OR
from sklearn.tree import DecisionTreeClassifier
clf = DecisionTreeClassifier(random_state=365)
So, as you can see, if you import only the "tree" part, you need to have tree.DecisionTreeClassifier, but if you import the DecisionTreeClassifier itself, you should leave out the "tree" in front.
Hope this helps!
Best,
Nikola, 365 Team