I'm trying to load the image of the Decision Tree in Python but I'm unable to do so.
The code is:
from IPython.display import Image
#import pydotplus as pydot
from sklearn import tree
from os import system
train_char_label = ['1', '2']
park_Tree_File = open('park_tree.dot','w')
dot_data = tree.export_graphviz(dt_model, out_file=park_Tree_File,
feature_names = list(train_set),
class_names = list(train_char_label))
park_Tree_File.close()
print (pd.DataFrame(dt_model.feature_importances_, columns = ["Imp"], index
= train_set.columns))
system("dot -Tpng park_tree.dot -o park_tree.png") # This command is to OS
Image("park_tree.png") # use the image command to read the .png file
# and print on screen
I get the following error:
TypeError: a bytes-like object is required, not 'str' for Image command in Python
Can you please suggest what is going wrong with the Image command?
The print command before that is working fine and printing the feature_importance perfectly.