Saving all models when using X-Partitioner

Hello,

I am trying to save all models from an X-Partitioner loop. What would be the best way to do that? the way I set it up saves only the last one.

Thanks!
Screen Shot 2021-06-28 at 19.08.33

1 Like

Hi @DataDudes and welcome to the KNIME forum!

One way to save the models within a loop is to convert them at every iteration into an object using the “PMML to Cell” node:

or the “Model to Cell” node:

Once a model is in cell format, you could add it into an extra column which is fed with a new model at every new loop iteration. Once all the iterations are finished, you should have a column with all the models saved. All these models can thus later be saved as a KNIME table using the table writer node:

You could at any time, read this table with your stored models using the Table Reader node:

And at this stage, using a new loop, convert them again into PMML format using the cell to PMML node:

or the Cell to Model node:

and finally execute them with their associated predictor. This procedure works for most of the models, regardless of the algorithm you are using to generate the model (here XGBoost Tree Ensemble Learner).

Here below a possible implementation:

B.t.w. this is just a possible solution, but there are a few others …

Hope this helps.

Best

Ael

Hi @DataDudes

I’m adding a workflow as an example of what I described in my last post:

20210628 Pikairos Saving all models when using X-Partitioner.knwf (606.4 KB)

Best

Ael

3 Likes

Thanks so much for your detailed answer and for sharing the workflow! I will test it and let you know how it worked. I also wonder if there’s a way to run a loop that saves models using the original model writer by changing the path of the model file.

1 Like

My pleasure.

Please find a modified version which implements too the writing of the current model at each iteration:

20210629 Pikairos Saving all models when using X-Partitioner.knwf (732.3 KB)

It adds too the local path with the name of the models to the final table with models, in case you would need the names too.

Hope this helps too :wink:

Best

Ael

2 Likes

Create a new file name inside the loop with string manipulation (variable) or java edit variable node. Use the iteration flow variable as part of file name: “model_iteration_” + iteration.

Then you get as many files as iterations. Question is why do you need all the models? It doesn’t make that much sense?

Thanks @DataDudes for validating the solution :smiley: :+1:!

All the best,

Ael

@kienerj might have a point. Maybe you have a particular reason. Do you want to elaborate on this? I am just curious.
Kudos to @aworker
Whenever I see X-Partitioner I still think of X-Aggregator as the only closing option so thanks for your workflow.

1 Like

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