# K-fold cross validation in one run?

**URL:** <https://community.wandb.ai/t/k-fold-cross-validation-in-one-run/3560>\
**Category:** W&B Help\
**Created:** [December 16, 2022, 2:14pm UTC](https://community.wandb.ai/t/k-fold-cross-validation-in-one-run/3560 "2022-12-16T14:14:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![soulios](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@soulios](https://community.wandb.ai/u/soulios)\
**Post date:** [December 16, 2022, 2:14pm UTC](https://community.wandb.ai/t/k-fold-cross-validation-in-one-run/3560/1 "2022-12-16T14:14:26Z")

</div>

Hello,  
I have set a run with a model to execute k-fold cross validation. When the axis of the AUC or loss plot is steps , all the folds are shown but when I select the axis to be equal to epochs, then only one run is shown. Which is this run? The last one, the average of all the runs or the best one?

 ![W&B Chart 12_16_2022, 3_12_11 PM](https://us1.discourse-cdn.com/flex020/uploads/wandb/original/2X/5/5f9d03b825103840e76e8a66e4499ab603ea22e9.png)  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![soulios](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@soulios](https://community.wandb.ai/u/soulios)\
**Post date:** [December 16, 2022, 2:16pm UTC](https://community.wandb.ai/t/k-fold-cross-validation-in-one-run/3560/2 "2022-12-16T14:16:05Z")

</div>

Because it did not let me post two images, I am posting here the initial graoh with all the folds.

 ![W&B Chart 12_16_2022, 3_11_58 PM](https://us1.discourse-cdn.com/flex020/uploads/wandb/original/2X/9/9a2a725f2461f1b385e18d9255d5ee960dcee3f1.jpeg)

---

<div class="post-metadata">

**Author:** ![ramit\_goolry](https://avatars.discourse-cdn.com/v4/letter/r/85e7bf/32.png) [@ramit\_goolry](https://community.wandb.ai/u/ramit_goolry)\
**Post date:** [December 19, 2022, 7:44pm UTC](https://community.wandb.ai/t/k-fold-cross-validation-in-one-run/3560/3 "2022-12-19T19:44:21Z")

</div>

Hey @soulios!

So from your description of the issue, looks like the epochs are being overwritten as the folds progress, leading to this issue. Here are 2 solutions that would work here:

1. Consider each fold as an individual run. You can use the `group` parameter to consolidate all your folds into individual experiments.
2. Log a different key for each fold as:

```plaintext
wandb.log({
  "Metric" : metric
  f"Fold {fold} Epoch" : epoch
})

```

or

```plaintext
wandb.log({
  f"Fold {fold} Metric" : metric
  f"Fold {fold} Epoch" : epoch
})

```

---

<div class="post-metadata">

**Author:** ![soulios](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@soulios](https://community.wandb.ai/u/soulios)\
**Post date:** [December 20, 2022, 7:52am UTC](https://community.wandb.ai/t/k-fold-cross-validation-in-one-run/3560/4 "2022-12-20T07:52:31Z")

</div>

Hey @ramit_goolry ! Thans for the reply. So the first plot refers to the last fold essentially?

---

<div class="post-metadata">

**Author:** ![ramit\_goolry](https://avatars.discourse-cdn.com/v4/letter/r/85e7bf/32.png) [@ramit\_goolry](https://community.wandb.ai/u/ramit_goolry)\
**Post date:** [December 27, 2022, 4:44am UTC](https://community.wandb.ai/t/k-fold-cross-validation-in-one-run/3560/5 "2022-12-27T04:44:48Z")

</div>

Yup, that’s correct.

---

<div class="post-metadata">

**Author:** ![ramit\_goolry](https://avatars.discourse-cdn.com/v4/letter/r/85e7bf/32.png) [@ramit\_goolry](https://community.wandb.ai/u/ramit_goolry)\
**Post date:** [January 2, 2023, 6:04pm UTC](https://community.wandb.ai/t/k-fold-cross-validation-in-one-run/3560/6 "2023-01-02T18:04:20Z")

</div>

Hi there, I wanted to follow up on this request. Please let us know if we can be of further assistance or if your issue has been resolved.

---

<div class="post-metadata">

**Author:** ![ramit\_goolry](https://avatars.discourse-cdn.com/v4/letter/r/85e7bf/32.png) [@ramit\_goolry](https://community.wandb.ai/u/ramit_goolry)\
**Post date:** [January 5, 2023, 2:40pm UTC](https://community.wandb.ai/t/k-fold-cross-validation-in-one-run/3560/7 "2023-01-05T14:40:55Z")

</div>

Hi @soulios, since we have not heard back from you we are going to close this request. If you would like to re-open the conversation, please let us know.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/wandb/original/1X/366b649231631dbab896843020da0056074ac79d.png) [@system](https://community.wandb.ai/u/system)\
**Post date:** [February 25, 2023, 4:45am UTC](https://community.wandb.ai/t/k-fold-cross-validation-in-one-run/3560/8 "2023-02-25T04:45:40Z")

</div>

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