【问题标题】:scikit-learn tree.DecisionTreeClassifier export to pdf too wide to fitscikit-learn tree.DecisionTreeClassifier 导出为 pdf 太宽不适合
【发布时间】:2017-11-09 02:29:10
【问题描述】:

我按照此线程中的说明进行了导出工作Python, PyDot and DecisionTree 但是 pdf 导出会在页面宽度后截断树,并且 png 太小而无法阅读。有没有办法创建一个无限宽度的pdf?

我的代码是

from sklearn import tree

clf = tree.DecisionTreeClassifier().fit(X_train, y_train)


import pydotplus
from IPython.display import Image
from sklearn.externals.six import StringIO
dot_data = StringIO()
tree.export_graphviz(clf, out_file=dot_data,feature_names=cols_scaled.columns) 
graph = pydotplus.graph_from_dot_data(dot_data.getvalue()) 
Image(graph.create_png())
graph.write_pdf("decisiontree.pdf")

非常感谢

【问题讨论】:

  • 对于png,必须有一些参数来控制尺寸
  • 如何使PNG不在控制台窗口中内联?我正在使用 Windows 10、Python 3.5 和 Spyder

标签: python scikit-learn


【解决方案1】:

尝试使用以下代码,PDF 需要宽度,如果有效,请告诉我。

from sklearn.externals.six import StringIO
import pydotplus   #using pydotplus in windows10, python 3.6.X
dot_data = StringIO()

tree.export_graphviz(clf, out_file=dot_data, 
                         feature_names=cols_scaled.column,  
                         class_names=<replace target column here>,  
                         filled=True, rounded=True,  
                         special_characters=True)  
graph = pydotplus.graph_from_dot_data(dot_data.getvalue())  
graph.write_pdf("iris.pdf")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-23
    • 2018-08-10
    • 2013-06-05
    • 2020-04-05
    • 2017-02-10
    • 2012-12-31
    • 2015-08-26
    相关资源
    最近更新 更多