# KNIME ML to Python

**URL:** <https://forum.knime.com/t/knime-ml-to-python/44220>\
**Category:** KNIME Analytics Platform\
**Tags:** machine-learning, python\
**Created:** [June 16, 2022, 9:19am UTC](https://forum.knime.com/t/knime-ml-to-python/44220 "2022-06-16T09:19:04Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![BrBr](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/b/c77e96/32.png) [@BrBr](https://forum.knime.com/u/BrBr)\
**Post date:** [June 16, 2022, 9:19am UTC](https://forum.knime.com/t/knime-ml-to-python/44220/1 "2022-06-16T09:19:05Z")

</div>

Dear KNIME-community

I created different machine learning models in KNIME. Now I want to export the model so I can use it in Python for the business. I’ve seen a few discussions about the other way round and export the model with the “Model Writer”-node. I used it but I’m not sure how to import it in python.

Do you have any idea to solve this problem?

Best 🙂

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [June 17, 2022, 1:39am UTC](https://forum.knime.com/t/knime-ml-to-python/44220/2 "2022-06-17T01:39:35Z")

</div>

@BrBr two options would be to use H2O.ai models or PMML

> [@Will Knime support saving or loading the model in pickle format?? I think the python script only support jython code as per documentation can someone tell me whether it will also support python code.](https://forum.knime.com/t/will-knime-support-saving-or-loading-the-model-in-pickle-format-i-think-the-python-script-only-support-jython-code-as-per-documentation-can-someone-tell-me-whether-it-will-also-support-python-code/13478/23):
>
> [Pickle](https://docs.python.org/3/library/pickle.html) is not a model or data format by itself but it would ‘wrap’ a Python object and store it to be brought back later. If you want to use models between KNIME and Python you should look for example think about using [PMML](https://forum.knime.com/t/export-pmml-that-outputs-class-probabilities/13244/2) - mostly I have used MOJO model files from H2O.ai which can easily be shared between KNIME and Python (or R) - if you use the correct MOJO version (which is not so obvious, unfortunately) - eg: KNIME 4.1\* \<-\> H2O 3.2\* (MOJO version 1.3) KNIME 4.2\* \<-\> H2O 3.3\* (MOJO versio…

> [@Decision tree learner seems to be overfitting](https://forum.knime.com/t/decision-tree-learner-seems-to-be-overfitting/38612/21):
>
> @akhtarameen you can import H2O.ai MOJO models into KNIME, R, Python and Spark (and back). That is why I like to use this format - for example I can develop a model on an R machine and then deploy it on a big data cluster. [This collection](https://kni.me/w/C__oI-oLpF-rrq1J) actually contains Jupiter notebook that basically does the same thing. So you might want to try that. There you might also see how to use relative paths in a notebook. This might be because of different splits in test and training, data prepar…

---

<div class="post-metadata">

**Author:** ![BrBr](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/b/c77e96/32.png) [@BrBr](https://forum.knime.com/u/BrBr)\
**Post date:** [June 17, 2022, 7:40am UTC](https://forum.knime.com/t/knime-ml-to-python/44220/3 "2022-06-17T07:40:28Z")

</div>

@mlauber71 thank you for your answer!  
Do I need specific nodes to write it with H2O? I used the “classic” nodes and no specific ones.

I created a good working Random Forest Classification Model and want to run it in python language. In the nodes I have in KNIME there’re some nodes for Gradient Boosted Trees or Simple regression trees. Maybe I’m just blind or need to download the right nodes…

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [June 17, 2022, 8:01am UTC](https://forum.knime.com/t/knime-ml-to-python/44220/4 "2022-06-17T08:01:27Z")

</div>

@BrBr you can use H2O models in KNIME and python and load them in both systems. A basic H2O workflow could look like this:

> **[20220107 Decision tree learner seems to be overfitting - test some more models...](https://hub.knime.com/mlauber71/spaces/Forum/2022/kn_forum_38612_ecg_classification_models~0wyHz2LfgNbricyE/current-state)**
>
> 20220107 Decision tree learner seems to be overfitting - test some more models https://forum.knime.com/t/decision-tree-learner-seems-to-be-overfitting/38612/12…

Maybe you also check this example and article. In the subfolder /script/ there is a jupyter notebook that shows the use in python also to import H2O MOJO model files.

> **[H2O.ai AutoML (wrapped with Python) in KNIME for classification problems –...](https://hub.knime.com/mlauber71/spaces/Public/automl/kn_automl_h2o_classification_python~MuIRrVEgfvOhtDXj/current-state)**
>
> H2O.ai AutoML (wrapped with Python) in KNIME for classification problems - a powerful auto-machine-learning framework (https://hub.knime.com/mlauber71/spaces/P…

> [@H2O.ai AutoML in KNIME for classification problems](https://forum.knime.com/t/h2o-ai-automl-in-knime-for-classification-problems/20923):
>
> H2O.ai Automl - a powerful auto-machine-learning framework wrapped with KNIME It features various models like Random Forest or XGBoost along with Deep Learning. It has wrappers for R and Python but also could be used from KNIME. The results will be written to a folder and the models will be stored in MOJO format to be used in KNIME (as well as on a Big Data cluster via Sparkling Water). One major parameter to set is the running time the model has to test various models and do some hyperparam…

---

<div class="post-metadata">

**Author:** ![BrBr](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/b/c77e96/32.png) [@BrBr](https://forum.knime.com/u/BrBr)\
**Post date:** [June 17, 2022, 1:32pm UTC](https://forum.knime.com/t/knime-ml-to-python/44220/5 "2022-06-17T13:32:36Z")

</div>

I’ve read all the examples from you but for me it’s not really clear how to use it on my data and with my specific model. I’m a chemist and wanted to improve our workflow. So for me it’s not really clear if and how I can use the trained model for the classification.  
Your created workflows are amazing and I think you invested a lot of time in it! Impressive! But maybe I’m to blind to see where the mode is saved to extract it to another platform. Can you tell me please?  
And maybe another question. At the moment I have a good model and I want to run it with new unknown samples. Is it also possible to improve constantly the model with the new data?  
Thank you very much for your help and sorry for those questions.

---

<div class="post-metadata">

**Author:** ![Daniel\_Weikert](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/d/e47c2d/32.png) [@Daniel\_Weikert](https://forum.knime.com/u/Daniel_Weikert)\
**Post date:** [June 17, 2022, 3:03pm UTC](https://forum.knime.com/t/knime-ml-to-python/44220/6 "2022-06-17T15:03:45Z")

</div>

If you export using pmml writer you should be able to import the file in python e.g. with

> **[sklearn-pmml-model](https://pypi.org/project/sklearn-pmml-model/)**
>
> A library to parse PMML models into Scikit-learn estimators.

br

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [June 18, 2022, 6:51am UTC](https://forum.knime.com/t/knime-ml-to-python/44220/7 "2022-06-18T06:51:49Z")

</div>

> [@BrBr](#):
>
> where the mode is saved to extract it to another platform. Can you tell me please?

I can try and make a more focused example of how to interact with models between KNIME and python.

The model gets saved as a MOJO file right there in [my first example](https://kni.me/w/0wyHz2LfgNbricyE). This zip file can later be used in KNIME or in another system that supports H2O like Python or R. And it works the other way round also.

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/f/b/fb2f6c4afa3f093d966dbca34b7f74f5f7f58f1c.jpeg)

Another option would be PMML for models which do support that. Issues here can be to have the right version and not all PMML models support probabilities which I often need.

---

<div class="post-metadata">

**Author:** ![BrBr](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/b/c77e96/32.png) [@BrBr](https://forum.knime.com/u/BrBr)\
**Post date:** [June 23, 2022, 6:45am UTC](https://forum.knime.com/t/knime-ml-to-python/44220/8 "2022-06-23T06:45:53Z")

</div>

Hi @mlauber71  
I could write it and now I want to test in in Python. Thank you for your help! After a closer look it was totally clear, maybe I spent to much time with KNIME and all the nodes and lost the overview 😃

---

<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:** [September 21, 2022, 6:46am UTC](https://forum.knime.com/t/knime-ml-to-python/44220/9 "2022-09-21T06:46:27Z")

</div>

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