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?


1 Answer 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.

  • $\begingroup$ Thank you for your detailed response... So recommend to not scale separately? As in scale all data together and then split? $\endgroup$ Commented Feb 20, 2021 at 9:00
  • 1
    $\begingroup$ 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. $\endgroup$ Commented Feb 21, 2021 at 8:10
  • $\begingroup$ 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.... $\endgroup$ Commented Feb 21, 2021 at 8:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .