1

我运行了一个 RandomForestClassifier,我想在 jupyter notebook 中可视化输出(决策树),但我不断收到错误消息。

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.

为什么我得到一个 NotFittedError,即使我已经安装了 RandomForestClassifier?

我对 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
4

0 回答 0