【问题标题】:Google Cloud Datalab - InvocationException: GraphViz's executables not foundGoogle Cloud Datalab - InvocationException:未找到 GraphViz 的可执行文件
【发布时间】:2018-08-31 23:40:56
【问题描述】:

我正在尝试使用 GraphViz 通过 Google Cloud Datalab 可视化决策树,但出现以下错误:

InvocationException:未找到 GraphViz 的可执行文件

我找到了related post,但是这里的解决方案并没有解决Datalab中的问题。

运行以下命令进行复制:

!pip install graphviz

import graphviz 
import numpy as np
from sklearn.datasets import load_iris
from sklearn import tree
from sklearn.externals.six import StringIO

iris = load_iris()
train_data = iris.data
train_labels = iris.target

clf = tree.DecisionTreeClassifier()
clf.fit(train_data, train_labels)

dot_data = tree.export_graphviz(clf, out_file=None, 
                         feature_names=iris.feature_names,  
                         class_names=iris.target_names)  
graph = graphviz.Source(dot_data)  
graph 

【问题讨论】:

  • 我们可以看一些代码吗?你试图执行什么?您是如何安装 graphviz 的?
  • 我添加了一个可以用来复制@yelsayed的样本

标签: google-cloud-datalab


【解决方案1】:

对我来说,它在运行这些单元后可以在 Datalab(Python2 内核)上运行:

%%bash
apt-get update -y

(这很可能会给您一个关于存储库未签名的错误,但您仍然可以使用--allow-unauthenticated 标志继续)

%%bash
apt-get install python-pydot -y --allow-unauthenticated

【讨论】:

【解决方案2】:

我在 Datalab 上运行 graphviz 时也遇到了同样的问题。在 Datalab 笔记本中导入 graphviz 库之前,请运行以下命令:

%%bash
/usr/bin/yes | apt-get install graphviz
pip install --upgrade graphviz
/usr/bin/yes | pip uninstall pyparsing
pip install -Iv https://pypi.python.org/packages/source/p/pyparsing/pyparsing-1.5.7.tar.gz
pip install --upgrade pydot

然后运行命令,它会像这样运行良好:

import graphviz
#visually representing the decision tree for num_leaves = 2
targetNames=['No Fault', 'Minor Fault','Major Fault']
dot_data = tree.export_graphviz(decTree, out_file= None,
                               feature_names=important_cols,
                               class_names = targetNames,
                               filled=True, rounded=True)
graph = graphviz.Source(dot_data)
graph

【讨论】:

    猜你喜欢
    • 2017-09-18
    • 2017-11-05
    • 2016-12-18
    • 2018-07-29
    • 2023-03-06
    • 2015-02-24
    • 2021-03-22
    • 2015-04-03
    • 2018-01-25
    相关资源
    最近更新 更多