3
votes

I have a question which I assume can be generic, but in my case it is applicable to neural network in R.

For the record I am using both h20 and neuralnet packages.

Since you may know, often, it is advised to scale he input of a neural network, in order to make the NN itself work better with the specific used activation function.

In R to do this there are several ways and I do use scale () / min / max.

Let's pretend that I have a matrix of 700x10 as input so the scaling will produce me two vectors scaled and center of carnality 10.

Now the problem starts when I want to unscale the output. The formula sayy vOutput * vScaled (full vector) + vCenter (full vector).

Question: Should I use then all the vectors (scaled and Center) in order to the unscaling? or there is a more complex formula or boundaries that I could not find?

1

1 Answers

0
votes
#sample data
df <- data.frame(col1 = c(1:5), col2 = c(11:15), target=c(1,0,0,0,1))

#normalize sample data using scale() - except the 'target' column
df_scaled <- scale(df[,-ncol(df)])
df_scaled

#revert back to original data from scaled version
df_original <- as.data.frame(t(apply(df_scaled, 1, 
                                     function(x) (x * attr(df_scaled, 'scaled:scale') + attr(df_scaled, 'scaled:center')))))
df_original