# Training and Testing separate ntuples

**URL:** <https://root-forum.cern.ch/t/training-and-testing-separate-ntuples/54160>\
**Category:** TMVA\
**Created:** [March 21, 2023, 11:55am UTC](https://root-forum.cern.ch/t/training-and-testing-separate-ntuples/54160 "2023-03-21T11:55:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fdeberna](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/65b543/32.png) [@fdeberna](https://root-forum.cern.ch/u/fdeberna)\
**Post date:** [March 21, 2023, 11:55am UTC](https://root-forum.cern.ch/t/training-and-testing-separate-ntuples/54160/1 "2023-03-21T11:55:41Z")

</div>

Dear experts,

I am doing a multivariate classification and I would like to know only if I am operating in the right way. For the classification I am using two different ntuples for signal training and testing (both having 30000 events) and one ntupla for background that should be splitted in half for training and testing.

I am operating in this way (considering only crucial lines):

```auto
TFile * Signal_Train = TFile::Open(...);
TFile * Signal_Test = TFile::Open(...);
TFile * Background = TFile::Open(...);

TCut mycutS = ""; //NO cuts
TCut mycutB = "cut";
dataloader->AddTree(Signal_Train->Get<TTree>("..."), "Signal", 1.0, mycutS,TMVA::Types::kTraining);
dataloader->AddTree(Signal_Test ->Get<TTree>("..."), "Signal", 1.0, mycutS, TMVA::Types::kTesting);

TTree* backgroundTree = (TTree*)Background ->Get("...");
dataloader->AddBackgroundTree(backgroundTree, backgroundWeight);

//remembering that: 
//signal training and testing ntuplas have 30000 events; background ntupla should be splitted in half:
dataloader->PrepareTrainingAndTestTree(mycutS, mycutB, "nTrain_Signal=30000:nTrain_Background=0:nTest_Signal=30000:nTest_Background=0:SplitMode=Random:NormMode=NumEvents:!V");

```

Could you please warn me if I am doing some errors somehwere?

Thank you a lot for any kind of help/suggestion  
Francesco

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [March 23, 2023, 10:05am UTC](https://root-forum.cern.ch/t/training-and-testing-separate-ntuples/54160/2 "2023-03-23T10:05:53Z")

</div>

I guess @moneta can help.

---

<div class="post-metadata">

**Author:** ![fdeberna](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/65b543/32.png) [@fdeberna](https://root-forum.cern.ch/u/fdeberna)\
**Post date:** [March 26, 2023, 10:29pm UTC](https://root-forum.cern.ch/t/training-and-testing-separate-ntuples/54160/3 "2023-03-26T22:29:32Z")

</div>

Thank you @couet @moneta for any suggestion

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [March 27, 2023, 9:30am UTC](https://root-forum.cern.ch/t/training-and-testing-separate-ntuples/54160/4 "2023-03-27T09:30:22Z")

</div>

Hi,  
TMVA normally automatically splits your signal and background data in training and test data. In your code above you are giving too TMVA your both signal training and test tree as signal tree. TMVA will split them randomly, according to the option you passed in `PrepapreTrainingAndTestTree`. Same thing will happen for the background. If this is what you want then the code is correct.  
If you want absolutely to split according to the two trees, I think you should use `MixMode=Block`, but the same splitting will happen also for the Background data.

Lorenzo
