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?
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:
- de-mean and save the feature means
- compute the feature variance or 'max abs value' and divide each feature column with it. Save this value as well.
- Now use the same feature means vector to de-mean the test set.
- 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)