A user is loading the following code but receives an error. How to fix that?

864    Asked by varshaChauhan in Data Science , Asked on Nov 4, 2019
Answered by varsha Chauhan

from sklearn.datasets import load_iris

from sklearn import tree
X, y = load_iris(return_X_y=True)
clf = tree.DecisionTreeClassifier()
clf = clf.fit(X, y)
The error is given below
NameError Traceback (most recent call last)
in
----> 1 tree.plot_tree(clf.fit(iris.data, iris.target))

NameError: name 'iris' is not defined

Here the error occurred because ‘iris’ does not exist because it is not assigned. For plotting we have to assign X and y instead of ‘iris’.

tree.plot_tree(clf.fit(X, y))Also we have to make sure the graphviz library bin folder is in PATH



Your Answer

Interviews

Parent Categories