Answers.Body: <p>Considering that you are making a minmax scaling, the only time in which there would be no risk of data leakage is if the minimum value on your training set equals the minimum value of the test set, and your maximum value on the training set equals the maximum value on the test set.</p>
  <p>In that circumstance the result of your scaling would be exactly the same as fitting the scaler to the training set, and applying it to the test set.</p>
  <p>There is basically no advantage in scaling them separately, and you take the risk of data leakage if their value ranges differ. I don't know much about genomic data, but even if your assumption was correct I would recommend not to do that.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-20T09:00:27.080Z
Answers.Text: Thank you for your detailed response... So recommend to not scale separately? As in scale all data together and then split?
Answers.UserDisplayName: user9317212
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-21T08:10:51.873Z
Answers.Text: Fit your scaler to the train data and then use the same scaler to the test data. If you scale all data together then you are also taking the risk of leakage.
Answers.UserDisplayName: Moonstone5629
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-21T08:34:43.977Z
Answers.Text: Thank you for clarification... I think I am still none the wiser given that I am scaling per sample (axis=1) - not per feature because of the nature of the data.. I think the justification is lacking for me, I don't really see why... Also the range per sample is slightly different, it's not the same across....
Answers.UserDisplayName: user9317212
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-20T05:58:14.300Z
Answers.LastActivityDate: 2021-02-20T05:58:14.300Z
Answers.UserDisplayName: Moonstone5629
Body: <p>I have a question about data leakage when pre-processing data for a neural network and whether data leakage actually applies in my instance.</p>
  <p>I have variance stabilising transformed genomic data. Because it is genomic data we know apriori that lower numbers translate to lower levels of a gene being made and vice versa. Before input into the neural network, the data are squashed to between 0 and 1 using sklearn:</p>
  <pre><code>preprocessing.minmax_scale(data, feature_range=(0,1), axis=1)
  </code></pre>
  <p>The min_max scaling needs to be done across sample <code>(axis=1)</code> as opposed to features because of this apriori assumption of gene levels - low genes need to remain low and vice-versa...</p>
  <p>Because of this, my question is: do training samples still need to be scaled separately from test samples as it doesn't seem there is a risk of data leakage here? Is this the correct assumption to make?</p>
  
Tags: <machine-learning><data-preprocessing><normalisation>
Title: Is data leakage relevant when scaling across samples?
UserDisplayName: user9317212
ThreadText: # Is data leakage relevant when scaling across samples?
  
  (Asked by: username_0 on 2021-02-19)
  
  I have a question about data leakage when pre-processing data for a neural network and whether data leakage actually applies in my instance.
  I have variance stabilising transformed genomic data. Because it is genomic data we know apriori that lower numbers translate to lower levels of a gene being made and vice versa. Before input into the neural network, the data are squashed to between 0 and 1 using sklearn:
  preprocessing.minmax_scale(data, feature_range=(0,1), axis=1)
  
  The min_max scaling needs to be done across sample (axis=1) as opposed to features because of this apriori assumption of gene levels - low genes need to remain low and vice-versa...
  Because of this, my question is: do training samples still need to be scaled separately from test samples as it doesn't seem there is a risk of data leakage here? Is this the correct assumption to make?
  
  **Tags:** machine-learning, data-preprocessing, normalisation
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-02-20. Score: 1
  
  Considering that you are making a minmax scaling, the only time in which there would be no risk of data leakage is if the minimum value on your training set equals the minimum value of the test set, and your maximum value on the training set equals the maximum value on the test set.
  
  In that circumstance the result of your scaling would be exactly the same as fitting the scaler to the training set, and applying it to the test set.
  
  There is basically no advantage in scaling them separately, and you take the risk of data leakage if their value ranges differ. I don't know much about genomic data, but even if your assumption was correct I would recommend not to do that.
  
  > **Comments:**
  > **username_0**: Thank you for your detailed response... So recommend to not scale separately? As in scale all data together and then split?  
  > **username_1**: Fit your scaler to the train data and then use the same scaler to the test data. If you scale all data together then you are also taking the risk of leakage.  
  > **username_0**: Thank you for clarification... I think I am still none the wiser given that I am scaling per sample (axis=1) - not per feature because of the nature of the data.. I think the justification is lacking for me, I don't really see why... Also the range per sample is slightly different, it's not the same across....  
  
  ---
  
  