# Plot Python Learner Decision Tree

**URL:** <https://forum.knime.com/t/plot-python-learner-decision-tree/27890>\
**Category:** KNIME Extensions\
**Tags:** machine-learning, python, visualization\
**Created:** [October 8, 2020, 2:24pm UTC](https://forum.knime.com/t/plot-python-learner-decision-tree/27890 "2020-10-08T14:24:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![V\_meyer](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/v/838e76/32.png) [@V\_meyer](https://forum.knime.com/u/V_meyer)\
**Post date:** [October 8, 2020, 2:24pm UTC](https://forum.knime.com/t/plot-python-learner-decision-tree/27890/1 "2020-10-08T14:24:21Z")

</div>

I have the following problem:

I used a Python Learner node and a Python Predictor node to run a (python) decision tree in KNIME on a training and test set. You can see my workflow here:

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/0/6/0681fc473ccc8c070ebf6d43949005d9b553af00.png)

If I do the same in KNIME (directly with the Decision Tree Learner+Predictor node) I can use a “Decision Tree View” node to plot the decision tree.

If I do the same with the R Learner and R Predictor node in KNIME, I can use the “R View (Workspace)” node and the “rpart.plot” function to plot the R decision tree.

Now I am wondering if there is any way to plot the decision tree model, that I trained with the Python learner node?  
Somehow I didn’t manage to export the Python decision tree model from the Python Learner node to a Python View or a Python Plot node.

Has anyone managed to do that and can help me?

Thanks in advance!

Best, Viviane

---

<div class="post-metadata">

**Author:** ![Corey](https://forum-cdn.knime.com/user_avatar/forum.knime.com/corey/32/71655_2.png) [@Corey](https://forum.knime.com/u/Corey)\
**Post date:** [October 16, 2020, 4:05pm UTC](https://forum.knime.com/t/plot-python-learner-decision-tree/27890/2 "2020-10-16T16:05:40Z")

</div>

Hi @V_meyer,

Assuming the Python package you’re using to train your decision tree supports the generation of that view you should be able to do this.

The problem, as you say, is how to get your trained model from the **Python Learner** node to the **Python View** node.

Unfortunately there’s no direct way to connect a python object port (model) to the data port on the **Python View** node. What you can do however is use an additional predictor node and the Pickle package to put that model into a dataframe, then unpickle it in the **Python Viewer** node before generating your view.

Would look something like this:

 ![Screen Shot 2020-10-16 at 10.59.51 AM](https://forum.knime.com/uploads/default/original/3X/8/6/86739e4f3ea38095430855bfb43bdfd67a1c795d.png)

It’s a bit of a round about solution - but I hope it helps!

---

<div class="post-metadata">

**Author:** ![V\_meyer](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/v/838e76/32.png) [@V\_meyer](https://forum.knime.com/u/V_meyer)\
**Post date:** [October 21, 2020, 9:04am UTC](https://forum.knime.com/t/plot-python-learner-decision-tree/27890/3 "2020-10-21T09:04:13Z")

</div>

Dear Corey

Thanks for your help!

With the pickle package and your example workflow it finally worked out.

Problem solved 🙂

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [October 28, 2020, 9:04am UTC](https://forum.knime.com/t/plot-python-learner-decision-tree/27890/4 "2020-10-28T09:04:14Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
