Last answered:

14 Jun 2022

Posted on:

10 Jun 2022

0

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)
Instructor
Posted on:

14 Jun 2022

0

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

Submit an answer