0

コードの目的は決定木モデルグラフを作成することです。 コードを以下に示します。実行にUnicodeデコードエラー:無効な開始バイト

dot_data=StringIO() 
tree.export_graphviz(clf,out_file=dot_data) 
graph=py.graph_from_dot_data(dot_data.getvalue()) 
print(graph) 
Image.open(graph.create_png(),mode='r') 

、それは次のエラーを与える:

Traceback (most recent call last): 
File "C:/Ankur/Python36/Python Files/Decision_Tree.py", line 58, in <module> 
Image.open(graph.create_png(),mode='r') 
File "C:\Ankur\Python36\lib\site-packages\PIL\Image.py", line 2477, in open 
fp = builtins.open(filename, "rb") 
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: 
invalid start byte 

私はそれを理解していないと、このエラーを解決するために苦労しています。

答えて

0

create_png()Image.openPIL)はファイル名またはファイルオブジェクトが必要ですが、bytesオブジェクトを返します。

import io 
Image.open(io.BytesIO(graph.create_png())) 

を試してみて、それが

を動作するはずです
関連する問題