# Overtraining check with CrossValidation

**URL:** <https://root-forum.cern.ch/t/overtraining-check-with-crossvalidation/35360>\
**Category:** TMVA\
**Created:** [July 26, 2019, 9:49am UTC](https://root-forum.cern.ch/t/overtraining-check-with-crossvalidation/35360 "2019-07-26T09:49:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![shu](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/e47c2d/32.png) [@shu](https://root-forum.cern.ch/u/shu)\
**Post date:** [July 26, 2019, 9:49am UTC](https://root-forum.cern.ch/t/overtraining-check-with-crossvalidation/35360/1 "2019-07-26T09:49:06Z")

</div>

Dear MVA experts,  
Now I’m tring to use CrossValidation for some classification work. However, from the output file of the tutorial code here: [https://root.cern/doc/master/TMVACrossValidation\_8C.html](https://root.cern/doc/master/TMVACrossValidation_8C.html), I found that the information in the output TrainTree and TestTree are completely the same. When I’m looking at the overtraining check plot from TMVAGui, the training part and testing part just overlap with each other.  
I’m wondering how to deal with the issue if I want to CrossValidation class.  
Many thanks in advance!

Cheers,  
Shuyang

---

<div class="post-metadata">

**Author:** ![mwilkins](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mwilkins/32/28332_2.png) [@mwilkins](https://root-forum.cern.ch/u/mwilkins)\
**Post date:** [July 26, 2019, 9:15pm UTC](https://root-forum.cern.ch/t/overtraining-check-with-crossvalidation/35360/2 "2019-07-26T21:15:30Z")

</div>

I would like to second this question. I believe that the testing and training samples show up as identical in the plot because there are no separate “training” and “testing” samples on which to evaluate. But this begs the question: are there built-in/recommended ways to check for overtraining in CrossValidation within ROOT?

---

<div class="post-metadata">

**Author:** ![mwilkins](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mwilkins/32/28332_2.png) [@mwilkins](https://root-forum.cern.ch/u/mwilkins)\
**Post date:** [July 26, 2019, 9:26pm UTC](https://root-forum.cern.ch/t/overtraining-check-with-crossvalidation/35360/3 "2019-07-26T21:26:08Z")

</div>

Also note that section 3.2 in the [TMVA Users Guide](https://root.cern.ch/root/html/guides/tmva/TMVAUsersGuide.pdf) provides an overview of this subject, including some discussion of performance evaluation.

---

<div class="post-metadata">

**Author:** ![kialbert](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kialbert/32/16537_2.png) [@kialbert](https://root-forum.cern.ch/u/kialbert)\
**Post date:** [August 14, 2019, 3:56pm UTC](https://root-forum.cern.ch/t/overtraining-check-with-crossvalidation/35360/4 "2019-08-14T15:56:00Z")

</div>

Hi,

> [@mwilkins](#):
>
> there are no separate “training” and “testing” samples on which to evaluate

Precisely so.

> [@mwilkins](#):
>
> are there built-in/recommended ways to check for overtraining in CrossValidation within ROOT?

If a separate, external, test set is not appropriate, one can evaluate each fold in separation to investigate the property you are interested in.

When using cross validation in TMVA, a separate model is trained for each fold and saved in e.g. `dataset/weights/YourModelName_Fold1.xml`. These can then be used with the `TMVA::Reader` get the individual output (it is beneficial here to split on some external quantity e.g. an event ID so that the input to each fold is easily recreated).

Cheers,  
Kim

---

<div class="post-metadata">

**Author:** ![mwilkins](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mwilkins/32/28332_2.png) [@mwilkins](https://root-forum.cern.ch/u/mwilkins)\
**Post date:** [August 14, 2019, 5:14pm UTC](https://root-forum.cern.ch/t/overtraining-check-with-crossvalidation/35360/5 "2019-08-14T17:14:31Z")

</div>

Hello,

The solution I arrived at is to use `FoldFileOutput=True` in the `CrossValidation` constructor and then compare the training and testing distributions in each fold. Unfortunately, this suppresses some useful output due to a bug which I reported [here](https://sft.its.cern.ch/jira/browse/ROOT-10254), though it hasn’t received any attention yet; thus I currently have to train twice: once to get the full printed output and once to get the distributions for each fold.

Thanks,  
Michael

---

<div class="post-metadata">

**Author:** ![kialbert](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kialbert/32/16537_2.png) [@kialbert](https://root-forum.cern.ch/u/kialbert)\
**Post date:** [August 15, 2019, 5:46pm UTC](https://root-forum.cern.ch/t/overtraining-check-with-crossvalidation/35360/6 "2019-08-15T17:46:46Z")

</div>

Great that you found a solution.

A fix for the problem you reported is currently under review.

Cheers,  
Kim
