I couldn't find an answer to the following issue and I kinda feel stuck...

I have a dataset and I want to split it as follows:

  • 90% for train and validation
  • 10% for test

Now, I want to use StratifiedKFold() on the 90%. Let's say I want 10 folds. I do the loop, get the indices, get the training and validation sets, use the StandardScaler() for each fold separately, train the model on each fold, get the average accuracy.

After I do all of these, how should I use the 10% left for testing, given the fact it wasn't standardized? What am I missing?

Thank you

  • $\begingroup$ To answer my question, I think I'm missing sleep. Is the correct answer the usual standardization as I did it per each fold? $\endgroup$ – qeddot Apr 16 '20 at 19:39

You have to normalize at each loop/fold your test set with the SAME normalization you applied to your training set, so something like this:

normalization = StandardScaler().fit(X_train)

X_train = normalization.transform(X_train)
X_test  = normalization.transform(X_test)

If you don't apply the same normalization to the test set then you will have fundamentally modified your test data.


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.