# Question about normalize/scale data before using neuralnet

I have read several threads about the issue on same outputs after people fitting a neural network model with R neuralnet. Posted Solution is to normalize or scale the data before fitting model. Since I am a newbie in this area, I feel confused in the inconsistence between the normalized training data and normalized testing data. The thing is people fit neuralnet after they normalizing training data. Then they use the fitted model on normalized testing data to forecast. Since the training data and testing data are separate, the normalizing or scale method might be different which might result in in-correctness of forecast. Can anyone help me about this concern?

• The Matlab's method mapstd solves this issue. I wonder whether there is an equivalent in R. Feb 22 '15 at 0:16
• but , if the MAXn/MINn of test data higher or lower thand max and min of the training data? THanks Feb 12 '17 at 1:58

You are right in identifying that it is incorrect to use two different normalizations, one for training and one for testing.

Here is the right approach. Normalize the training set, by which I mean:

1. de-mean and save the feature means
2. compute the feature variance or 'max abs value' and divide each feature column with it. Save this value as well.
3. Now use the same feature means vector to de-mean the test set.
4. Use the same feature variance or 'max abs value' computed with training data to divide the testing feature column.

Note: I assumed certain type of normalization (de-meaning each feature column and diving by the variance of the feature column), but the general idea remains the same.

I found preProcess of caret package that seems to do what you want.

The way to use this method is the following

procValues <- preProcess(trainData, method = c("center", "scale"))
scaledTraindata <-  predict(procValues, trainData)
scaledTestdata <-  predict(procValues, testData)