Plot Python Learner Decision Tree

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:

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

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:

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

4 Likes

Dear Corey

Thanks for your help!

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

Problem solved :slight_smile:

2 Likes

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