2
$\begingroup$

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?

$\endgroup$
0
1
$\begingroup$

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.