def tree_image(tree, fout=None):
    try:
        import pydot
        import a_reliable_dot_rendering
    except __HOLE__:
        return None
    dot_data = StringIO()
    export_graphviz(tree, out_file=dot_data)
    data = re.sub(r"gini = 0\.[0-9]+\\n", "", dot_data.getvalue())
    data = re.sub(r"samples = [0-9]+\\n", "", data)
    data = re.sub(r"\\nsamples = [0-9]+", "", data)

    graph = pydot.graph_from_dot_data(data)
    if fout is None:
        fout = "tmp.png"
    graph.write_png(fout)
    return imread(fout)
dataset/ETHPy150Open amueller/nyu_ml_lectures/plots/plot_interactive_tree.py/tree_image