Answers.Body: <p><strong>Short answer:</strong> Yes, the validation set should be the same otherwise you risk that a &quot;lucky&quot; set of validation samples is responsible for better performance.</p>
  <p><strong>Long answer:</strong> A fair comparison of 2 or more models can only occur if these are <em>both</em> trained and evaluated in <em>exactly</em> the same conditions. That is:</p>
  <ul>
  <li><em>Same training data</em>, shuffled and batched in the same order just because of the stochastic nature of the optimizers.</li>
  <li><em>Same initialization of weights</em>, or at least, in case of models with different architectures/layers, from the same pseudo-random generator's (PRNG) state.</li>
  <li><em>Validation should occur in the same way</em>: data should be the same, as well as the model selection criterion.</li>
  </ul>
  <p>In general, all the stochastic operations (SGD, weight init, train-test splits, samplings, etc) should be <em>reproducible</em>, for two reasons: 1) the performance of your model should not depend on random numbers that change every run, and 2) you want to avoid having both a lucky or unlucky training just due to the PRNG. To (almost) solve this, one has to set the same random seed for all the random generators. This may be not enough, due to some inherently non-deterministic operations (e.g. some calculations on GPU due to CUDA optimizations, parallelism, etc) but more importantly the (sequence) of PRNG states should be the same across runs and comparisons: Python or numpy's PRNG are stateful, meaning that each time you ask for random numbers they change their internal state. In particular the numpy's PRNG consumes entropy, being more and more deterministic as it is used. One should do as JAX forces: use stateless PRNGs, and manually keep track of the state.</p>
  <p>Regarding statement 2, ou have to consider that a single run of a model gives a <em>punctual estimation</em> of the real performance of the model: what you want to know is an <em>expected</em> value, instead, i.e. something associated with a standard deviation for example. This is for a more broad discussion, but to properly compare two or more models (methods, etc) a single number (e.g. AUC) is not enough because you cannot decide whether M1 is really better than M2 because of the superior architecture or better hyper-params, or because it was just a lucky random seed or lucky data: since your training and validation sets are not infinite, model performance are subject to inherent fluctuations. Instead, training a model 100 times, for example, considering different initial situations (but different across the runs, and not along compared models), allows you to aggregare performance obtaining a mean and associated std. For example, M1 can achieve 95% (<span class="math-container">$\pm 3$</span>) AUC while M2 achieves 95% (<span class="math-container">$\pm 1$</span>). So what model you choose? both achieve the same performance on average, but M1 has more variability; there are approaches that perform statistical tests to say that M1 has a probability <span class="math-container">$p$</span> to beat M2, and M2 has a prob <span class="math-container">$p_1$</span> to be better. According to such probability you can make a decision, for example.</p>
  <p>To conclude, this is an open question (also because 100 runs are not practical).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-05T21:02:39.873Z
Answers.LastActivityDate: 2023-05-05T21:02:39.873Z
Answers.UserDisplayName: Luca Anzalone
Body: <p>I, i have a doubt about making validation using early stopping given two NN models.</p>
  <p>Suppose I have two models M1 and M2 and a Training set TS and Test set TS.</p>
  <p>Take the TS and consider TS_80% and TS_20%, the first as training and the second as validation in the hold out procedure</p>
  <p>Train M1 with early stopping on TS_80, choosing 10% of TS_80 as validation reference set for the early stopping procedure, we could call this <strong>TS_80_es_1</strong></p>
  <p>Then train M2 with early stopping on TS_80, choosing 10% of TS_80 as validation reference set for the early stopping procedure, calling it <strong>TS_80_es_2</strong>.</p>
  <p><strong>NOW, must TS_80_es_1 be identical to TS_80_es_2</strong>? I mean, the validation set we use for the early stopping must be the same or can it be chosen as 10% randomly in each individual training for each model and so we can consider different validation sets in the early stopping procedure?</p>
  <p><strong>In other words, every model we train using early stopping has the same validation set for early stopping procedure, or the validation set can be different for each training phase?</strong></p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-05-04T17:18:06.707Z
Comments.Text: Do you use the same early stop criterion for both models?
Comments.UserDisplayName: Luca Anzalone
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-05-04T19:39:55.233Z
Comments.Text: @LucaAnzalone Yes, the criterion is the same (a very superficial one , |validation_loss_epoch_x - validation_epoch_time_x+5| < threshold, if there is no significant increase in 5 epochs, then stop)
Comments.UserDisplayName: PwNzDust
Tags: <neural-networks><regularization><early-stopping>
Title: Do different models using early stopping have the same validation set to check model training performance?
UserDisplayName: PwNzDust
ThreadText: # Do different models using early stopping have the same validation set to check model training performance?
  
  (Asked by: username_0 on 2023-05-04)
  
  I, i have a doubt about making validation using early stopping given two NN models.
  
  Suppose I have two models M1 and M2 and a Training set TS and Test set TS.
  
  Take the TS and consider TS\_80% and TS\_20%, the first as training and the second as validation in the hold out procedure
  
  Train M1 with early stopping on TS\_80, choosing 10% of TS\_80 as validation reference set for the early stopping procedure, we could call this **TS\_80\_es\_1**
  
  Then train M2 with early stopping on TS\_80, choosing 10% of TS\_80 as validation reference set for the early stopping procedure, calling it **TS\_80\_es\_2**.
  
  **NOW, must TS\_80\_es\_1 be identical to TS\_80\_es\_2**? I mean, the validation set we use for the early stopping must be the same or can it be chosen as 10% randomly in each individual training for each model and so we can consider different validation sets in the early stopping procedure?
  
  **In other words, every model we train using early stopping has the same validation set for early stopping procedure, or the validation set can be different for each training phase?**
  
  **Tags:** neural-networks, regularization, early-stopping
  > **Comments:**
  > **username_1**: Do you use the same early stop criterion for both models?  
  > **username_0**: @LucaAnzalone Yes, the criterion is the same (a very superficial one , |validation_loss_epoch_x - validation_epoch_time_x+5| < threshold, if there is no significant increase in 5 epochs, then stop)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-05-05. Score: 3 | Accepted answer
  
  **Short answer:** Yes, the validation set should be the same otherwise you risk that a "lucky" set of validation samples is responsible for better performance.
  
  **Long answer:** A fair comparison of 2 or more models can only occur if these are *both* trained and evaluated in *exactly* the same conditions. That is:
  
  * *Same training data*, shuffled and batched in the same order just because of the stochastic nature of the optimizers.
  * *Same initialization of weights*, or at least, in case of models with different architectures/layers, from the same pseudo-random generator's (PRNG) state.
  * *Validation should occur in the same way*: data should be the same, as well as the model selection criterion.
  
  In general, all the stochastic operations (SGD, weight init, train-test splits, samplings, etc) should be *reproducible*, for two reasons: 1) the performance of your model should not depend on random numbers that change every run, and 2) you want to avoid having both a lucky or unlucky training just due to the PRNG. To (almost) solve this, one has to set the same random seed for all the random generators. This may be not enough, due to some inherently non-deterministic operations (e.g. some calculations on GPU due to CUDA optimizations, parallelism, etc) but more importantly the (sequence) of PRNG states should be the same across runs and comparisons: Python or numpy's PRNG are stateful, meaning that each time you ask for random numbers they change their internal state. In particular the numpy's PRNG consumes entropy, being more and more deterministic as it is used. One should do as JAX forces: use stateless PRNGs, and manually keep track of the state.
  
  Regarding statement 2, ou have to consider that a single run of a model gives a *punctual estimation* of the real performance of the model: what you want to know is an *expected* value, instead, i.e. something associated with a standard deviation for example. This is for a more broad discussion, but to properly compare two or more models (methods, etc) a single number (e.g. AUC) is not enough because you cannot decide whether M1 is really better than M2 because of the superior architecture or better hyper-params, or because it was just a lucky random seed or lucky data: since your training and validation sets are not infinite, model performance are subject to inherent fluctuations. Instead, training a model 100 times, for example, considering different initial situations (but different across the runs, and not along compared models), allows you to aggregare performance obtaining a mean and associated std. For example, M1 can achieve 95% ($\pm 3$) AUC while M2 achieves 95% ($\pm 1$). So what model you choose? both achieve the same performance on average, but M1 has more variability; there are approaches that perform statistical tests to say that M1 has a probability $p$ to beat M2, and M2 has a prob $p\_1$ to be better. According to such probability you can make a decision, for example.
  
  To conclude, this is an open question (also because 100 runs are not practical).
  
  
  ---
  
  