# Scale test set using training mean and std in Python [closed]

To scale the training set with its own mean and inverse std i used:

scaledTrainx = preprocessing.scale(trainx)


However, this won't work for the test data as:

scaledTrainx = preprocessing.scale(testx)


Will scale the test data based on its own mean and STD instead of the training set's mean and std, correct?

If so, how do i scale the test set using the training mean and std?

Thanks.

## closed as off-topic by Tim♦Sep 11 '18 at 10:51

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – Tim
If this question can be reworded to fit the rules in the help center, please edit the question.

• I think the reason you have been put on hold is that you assumed users on CrossValidated know about specific python libraries. Your actual question was Do I scale the test set using the training mean and std? That question doesn't require any specific python knowledge – Alexander McFarlane Sep 11 '18 at 10:58
• @AlexanderMcFarlane I mean HOW do i scale the test set using the training mean and std. I am following assignment specifications that tell me to do so. – badprogrammerman Sep 11 '18 at 11:00
• @badprogrammerman Programming questions are considerd off-topic here. StackOverflow should be the right place to ask. – Jan Kukacka Sep 11 '18 at 11:32
• Your instructions are correct, you should use the training set statistics for scaling of the test set. Also, you forgot to tell which python library are you using, so it is not possible to answer... – Jan Kukacka Sep 11 '18 at 11:34
• @JanKukacka I asked this at stackoverlow and i got sent here.... – badprogrammerman Sep 12 '18 at 5:48