# Negative weight when using BDTG

**URL:** <https://root-forum.cern.ch/t/negative-weight-when-using-bdtg/36389>\
**Category:** TMVA\
**Created:** [October 17, 2019, 3:36pm UTC](https://root-forum.cern.ch/t/negative-weight-when-using-bdtg/36389 "2019-10-17T15:36:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xinst](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/x/e480ec/32.png) [@xinst](https://root-forum.cern.ch/u/xinst)\
**Post date:** [October 17, 2019, 3:36pm UTC](https://root-forum.cern.ch/t/negative-weight-when-using-bdtg/36389/1 "2019-10-17T15:36:35Z")

</div>

Dear Experts,  
I meet a problem with tmva. My train samples contain some negative weights. After applying BDTG , the “overtraining check” failed:  
— Found directory for method: BDT::BDTG containing MVA\_BDTG\_S/\_B  
— Mean and RMS (S): 0.21677, 0.335244  
— Mean and RMS (B): -0.277857, 0.381702  
— Found comparison histograms for overtraining check  
— Perform Kolmogorov-Smirnov tests  
Error in TH1D::ComputeIntegral: Bin content is negative - return a NaN value

So what is the reason Mean(B) is less than 0?

Best,  
Leon

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [October 17, 2019, 3:43pm UTC](https://root-forum.cern.ch/t/negative-weight-when-using-bdtg/36389/2 "2019-10-17T15:43:16Z")

</div>

Welcome to the ROOT forum! And I think @moneta will be happy to help you!

---

<div class="post-metadata">

**Author:** ![xinst](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/x/e480ec/32.png) [@xinst](https://root-forum.cern.ch/u/xinst)\
**Post date:** [October 17, 2019, 4:36pm UTC](https://root-forum.cern.ch/t/negative-weight-when-using-bdtg/36389/3 "2019-10-17T16:36:54Z")

</div>

Glad to hear that 😄 I am quiet new to TMVA. The environment is tmva4.20 with root5.34.

---

<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:** [October 21, 2019, 1:17pm UTC](https://root-forum.cern.ch/t/negative-weight-when-using-bdtg/36389/4 "2019-10-21T13:17:32Z")

</div>

Hi and welcome to the ROOT (online) community!

The reason for the error is most probably that you are using negative weights.

You can either:

1. specify the bin width of the generated histograms by inserting (adapted from [Kolmogorov-Smirnov test values](https://root-forum.cern.ch/t/kolmogorov-smirnov-test-values/32868/4)) `TMVA::gConfig().GetVariablePlotting()).fNbinsMVAoutput = 25;` at the top of your training script (default is `fNbinsMVAoutput = 40`),

2. or use a larger training sample!

## Details

Negative event weights are sometimes included as correction terms in simulations, however, the events themselves are unphysical. A histogram modelling a probability distribution cannot contain bins with a negative sum, the events with negative weight only make sense in _on average_. This is what TMVA is complaining about! (The implication is that with the current training data the region in the histogram having a negative sum is poorly modelled.)
