# Cross Validation Loop - How to take flow variables outside the loop

**URL:** <https://forum.knime.com/t/cross-validation-loop-how-to-take-flow-variables-outside-the-loop/58338>\
**Category:** KNIME Analytics Platform\
**Created:** [January 5, 2023, 6:19am UTC](https://forum.knime.com/t/cross-validation-loop-how-to-take-flow-variables-outside-the-loop/58338 "2023-01-05T06:19:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aravind98](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/7ea924/32.png) [@aravind98](https://forum.knime.com/u/aravind98)\
**Post date:** [January 5, 2023, 6:19am UTC](https://forum.knime.com/t/cross-validation-loop-how-to-take-flow-variables-outside-the-loop/58338/1 "2023-01-05T06:19:16Z")

</div>

Hi KNIME community,

I was checking out the various ML nodes and I wanted to see what differences changing the different parameters of the learner and partitioner node makes to the result. I made a workflow in which these parameters are defined, taken from the learner node as flow variables, and combined with the results from the predictor node. I can then read these to an Excel or CSV and then compare the results with different configs with less manual correction.

 ![KNIME1](https://forum-cdn.knime.com/uploads/default/original/3X/0/5/05b8cac5eca23885775711d78a4cdb84fdc7da44.png)

This worked fine when I was using a simple Partitioner node. But then I wanted to try it with cross-validation, and this approach would not work with the X-Partitioner X-Aggregator loop as I am taking the flow variables outside the loop. I assume I have to nest this loop with another loop (Generic Loop Start - Loop Variable nodes, maybe), but I am unable to figure out how to set this up.

So very basically, I want to take the parameters from the leaner and partitioner nodes outside the Cross Validation loop. Is it possible? Or is there a better approach to capture these parameters? I am attaching the workflow here.

Thanks!

[Cross Validation Loop.knwf](https://forum.knime.com/uploads/short-url/33ncEkxb0wUVpSLymOi97I24Unk.knwf) (1.2 MB)

---

<div class="post-metadata">

**Author:** ![Kathrin](https://forum-cdn.knime.com/user_avatar/forum.knime.com/kathrin/32/16014_2.png) [@Kathrin](https://forum.knime.com/u/Kathrin)\
**Post date:** [January 5, 2023, 7:15am UTC](https://forum.knime.com/t/cross-validation-loop-how-to-take-flow-variables-outside-the-loop/58338/2 "2023-01-05T07:15:02Z")

</div>

Hi @aravind98 and welcome to the KNIME Community Forum 🙂

My idea would be to move the part of the workflow that writes the variables to a table into the loop body, e.g. like that:

 ![Screen Shot 2023-01-05 at 08.13.52](https://forum-cdn.knime.com/uploads/default/original/3X/b/5/b56a80ea59efb965b990d1fbb79744839b9e5032.jpeg)

Cheers  
Kathrin

Adjusted Workflow:  
[Cross Validation Loop.knwf](https://forum.knime.com/uploads/short-url/lm7MA9RyA81KZ9wOo6RsXpyYwAE.knwf) (1.3 MB)

---

<div class="post-metadata">

**Author:** ![aworker](https://forum-cdn.knime.com/user_avatar/forum.knime.com/aworker/32/36421_2.png) [@aworker](https://forum.knime.com/u/aworker)\
**Post date:** [January 5, 2023, 8:11am UTC](https://forum.knime.com/t/cross-validation-loop-how-to-take-flow-variables-outside-the-loop/58338/3 "2023-01-05T08:11:47Z")

</div>

Hi @aravind98 & welcome to the KNIME forum community

Complementary to @Kathrin solution, please find here below a workflow which combines a -X-Partitioner- loop node with a -Loop End- node to differently gather any information generated during the cross-validation:

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

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/e/b/eb1e78e26fea769ca11d30551a691fe7a277dd1b.png)

> **[20230105 Pikairos Cross Validation Loop - How to take flow variables outside...](https://hub.knime.com/pikairos/spaces/Public/latest/20230105%20Pikairos%20Cross%20Validation%20Loop%20-%20How%20to%20take%20flow%20variables%20outside%20the%20loop~ijXGOhRgA0UNdpV4)**
>
> This workflow shows how to combine a -X-Partitioner- node to a -Loop End- node to individually gather information (Data / Variables / Images) from the differen…

Moreover, it is possible too to save the intermediate models (one per iteration) as shown here in the workflow below:

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/f/a/fa553a2b69bfe3ad473931452a8cc23d57377801.png)

> **[20210628 Pikairos Saving all models when using X-Partitioner – pikairos](https://hub.knime.com/pikairos/spaces/Public/latest/20210629%20Pikairos%20Saving%20all%20models%20when%20using%20X-Partitioner~RgpZqxIZLYmum-SP)**
>
> This workflow shows how to combine a -X-Partitioner- node to a -Loop End- node to individually gather scoring information and models from the different Cross V…

Hope it helps.

Best  
Ael

---

<div class="post-metadata">

**Author:** ![aravind98](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/7ea924/32.png) [@aravind98](https://forum.knime.com/u/aravind98)\
**Post date:** [January 5, 2023, 12:34pm UTC](https://forum.knime.com/t/cross-validation-loop-how-to-take-flow-variables-outside-the-loop/58338/5 "2023-01-05T12:34:35Z")

</div>

@Kathrin @aworker Thank you for your help! This will work for me.

---

<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:** [January 12, 2023, 12:34pm UTC](https://forum.knime.com/t/cross-validation-loop-how-to-take-flow-variables-outside-the-loop/58338/6 "2023-01-12T12:34:47Z")

</div>

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