如何在Jupyter Notebook中可视化决策树?

时间:2018-10-22 08:41:45

标签: python graph jupyter-notebook random-forest decision-tree

我运行了RandomForestClassifier,我想在jupyter笔记本中可视化输出(决策树),但是我一直遇到错误。

rnd_clf=RandomForestClassifier(n_estimators=500, max_leaf_nodes=16, n_jobs=-1)
rnd_clf.fit(X,y) 
clf_graph=export_graphviz(rnd_clf,
            feature_names=X.columns,
            filled=True,
            rounded=True, 
            out_file=None)

graph=graphviz.Source(clf_graph)
graph.render("clf_graph")

我收到以下错误:

NotFittedError: This RandomForestClassifier instance is not fitted yet. Call 'fit' with appropriate arguments before using this method.

即使安装了RandomForestClassifier,为什么仍会收到NotFittedError?

我对DecisionTreeClassifier进行了相同的操作,但得到了另一个错误:

clf = DecisionTreeClassifier(criterion='entropy')
clf = clf.fit(X,y)
clf_graph=export_graphviz(clf,
            feature_names=X.columns,
            filled=True,
            rounded=True, 
            out_file=None)

graph=graphviz.Source(clf_graph)
graph.render("clf") 

我收到以下错误:

ExecutableNotFound: failed to execute ['dot', '-Tpdf', '-O', 'clf'], make sure the Graphviz executables are on your systems' PATH

0 个答案:

没有答案