# Nan entries in the dataset

**URL:** <https://root-forum.cern.ch/t/nan-entries-in-the-dataset/39576>\
**Category:** TMVA\
**Created:** [May 24, 2020, 8:40pm UTC](https://root-forum.cern.ch/t/nan-entries-in-the-dataset/39576 "2020-05-24T20:40:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saumyenk](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/3bc359/32.png) [@Saumyenk](https://root-forum.cern.ch/u/Saumyenk)\
**Post date:** [May 24, 2020, 8:40pm UTC](https://root-forum.cern.ch/t/nan-entries-in-the-dataset/39576/1 "2020-05-24T20:40:46Z")

</div>

Hi,  
I was running the classification macro with my dataset that has ‘nan’ entries. And I got the error as in below:

```auto
<FATAL> : How am I supposed to train a NaN or +-inf?!

```

So, can’t a ‘nan’ value be passed through the DataLoader in TMVA? I’m not much experienced with TMVA. Can you suggest to me how should I deal with the ‘nan’ values in TMVA?

Regards,  
Saumyen

---

<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:** [May 26, 2020, 7:21am UTC](https://root-forum.cern.ch/t/nan-entries-in-the-dataset/39576/2 "2020-05-26T07:21:22Z")

</div>

Hi,

You should remove the events containing a NaN with a cut. For example when calling DataLoader::PrepareTrainingAndTestTree you can pass cuts for signal and background events. There you should exclude events containig NaN, using for example the TMath function `TMath::IsNaN(var)`

Lorenzo

---

<div class="post-metadata">

**Author:** ![Saumyenk](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/3bc359/32.png) [@Saumyenk](https://root-forum.cern.ch/u/Saumyenk)\
**Post date:** [May 26, 2020, 8:01am UTC](https://root-forum.cern.ch/t/nan-entries-in-the-dataset/39576/3 "2020-05-26T08:01:19Z")

</div>

Thank you so much Lorenzo for the reply and suggestion.  
So, these are the concerned lines that you suggested a modification.

```auto
   TCut preselectionCut = ""; 

   // To also specify the number of testing events, use:
   dataloader->PrepareTrainingAndTestTree( preselectionCut, "nTrain_Signal=6000:nTrain_Background=6000:SplitMode=Random:NormMode=NumEvents:!V" );

```

Now how should I put the cut, I mean the command? Is it like whichever variables I am taking for those should I put

```auto
   TCut preselectionCut = "TMath::IsNaN(PT_l) = False" ;

```

if `PT_l` is one of the variables?

Regards,  
Saumyen

---

<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:** [May 26, 2020, 8:42am UTC](https://root-forum.cern.ch/t/nan-entries-in-the-dataset/39576/4 "2020-05-26T08:42:17Z")

</div>

The cut should be defined as following (supposing PT\_1 and PT\_2 are the variables having NaN):

```auto
TCut preselectionCut = "!TMath::IsNaN(PT_1) && !TMath::IsNaN(PT_2)"

```

Lorenzo

---

<div class="post-metadata">

**Author:** ![Saumyenk](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/3bc359/32.png) [@Saumyenk](https://root-forum.cern.ch/u/Saumyenk)\
**Post date:** [May 28, 2020, 2:42pm UTC](https://root-forum.cern.ch/t/nan-entries-in-the-dataset/39576/5 "2020-05-28T14:42:58Z")

</div>

Thank you so much Lorenzo. It worked perfectly.

Thanks a lot,  
Saumyen

---

<div class="post-metadata">

**Author:** ![mlouka](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@mlouka](https://root-forum.cern.ch/u/mlouka)\
**Post date:** [March 20, 2024, 4:40pm UTC](https://root-forum.cern.ch/t/nan-entries-in-the-dataset/39576/6 "2024-03-20T16:40:24Z")

</div>

For me even putting cuts such that the values are not NaN nor inf. dose not remove all of them, instead one can just put a cuts such that these variable with the problem within ] 0 , 1000 [ for example
