python - 来自 sklearn 的 Graphviz 找不到我的文件?
问题描述
所以我正在尝试使用 sklearn 在 python 中构建决策树。
from sklearn.tree import DecisionTreeClassifier, export_graphviz
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
import graphviz
cancer = load_breast_cancer()
X_train, X_test, y_train, y_test = train_test_split(cancer.data, cancer.target,
stratify=cancer.target, random_state=42)
tree = DecisionTreeClassifier(random_state=0, max_depth=4)
tree.fit(X_train, y_train)
export_graphviz(tree, out_file=r"C:\Users\obaro\OneDrive\Documents\tree.dot", class_names=["malignant", "benign"],
feature_names=cancer.feature_names, impurity=False, filled=True)
with open(r"C:\Users\obaro\OneDrive\Documents\tree.dot") as f:
dot_graph = f.read()
display(graphviz.Source(dot_graph))
但是,当我尝试在 Jupyter 中运行此代码时,我收到 FileNotFound 错误和 ExecutableNotFound 错误。起初,我尝试使用相对路径,但没有成功,所以我尝试使用绝对路径。该文件已创建并位于我当前的主目录中,因此我不确定这里发生了什么。任何帮助将不胜感激,谢谢。
解决方案
推荐阅读
- php - 使用 add_filter 围绕 woocommerce_after_shop_loop_item 创建一个包装器
- shader - 如何从 ID3D11ShaderReflection 获得着色器类型(顶点/像素等)?
- mysql - 列表框 Laravel 数据
- javascript - 使用 .NET 在 Autodesk Forge 上下载文件
- javascript - Angular Material 2 工具提示问题
- spring - 在 Spring MVC 中使用 Hibernate 进行 MySQL 列加密
- flutter - FutureBuilder:即使在推送导航器之后也调用未来函数
- java - 如何将 spring 存储库条目的 id 设置为精确值?
- sql - 使用聚合函数时 CTE 行为异常
- ipad - 离子图标未显示在 ipad / edge 上