我无法重现一个简单的例子。事情是这样的:
import pandas as pd
import numpy as np
import sklearn as skl
from sklearn import tree
from sklearn.cross_validation import train_test_split as tts
# import data and give a little overview
sample = pd.read_stata('sample_data.dta')
s = sample
# Let's learn
X = np.array((s.crisis, s.cash, s.industry, s.current_debt, s.activity)).reshape(1000, 5)
y = np.array(s.wc_measure)
X_train, X_test, y_train, y_test = tts(X, y, test_size = .8)
my_tree = tree.DecisionTreeClassifier()
clf = my_tree.fit(X_train, y_train)
predictions = my_tree.predict(X_test)
# Graph the tree
from sklearn.externals.six import StringIO
import pydotplus
dotfile = StringIO()
tree.export_graphviz(clf, out_file=dotfile)
pydotplus.graph_from_dot_data(dotfile.getvalue()).write_png("my_tree.png")
当我尝试绘制 TreeMap 时,出现以下错误:
pydotplus.graphviz.InvocationException: GraphViz's executables not found
知道问题是什么吗?我完全遵循 graphviz 的文档。
最佳答案
看来你根本没有安装graphviz软件。你应该download并在使用该模块之前安装它。
关于python-3.x - 如何使用 graphviz 绘制 TreeMap ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39146728/