denormalization - Denormalize values after prediction in R -


i not sure whether denormalizing data correctly. have 1 output variable , several input variables. normalizing them using rsnns package. suppose x input matrix (nxm) each of n rows object m features. , y vector (n) corresponding answers.

nx <- normalizedata(x, type='0_1') 

after that, of data used make model , prediction. suppose pred.ny predicted values. these values normalized.

pred.y <- denormalizedata(pred.ny, getnormparameters(nx)) 

is correct? how work? it's clear 1 input can use min , max values used normalization. how work if each input normalized separately, using own min , max value?

update here toy-example, '0_1' looks better 'norm'. 'norm' make huge training error , constant prediction.

x <- runif(1020, 1, 5000) y <- sqrt(x) nx <- normalizedata(x, type='0_1') ny <- normalizedata(y, type='0_1') model <- mlp(nx[1:1000], ny[1:1000], size = 1) plotiterativeerror(model) npy <- predict(model, matrix(nx[1001:1020], ncol=1)) py <- denormalizedata(npy, getnormparameters(ny)) print(cbind(y[1001:1020], py)) 

there 2 things going on here:

  1. training model, i.e. setting internal coefficients in neural network. use both inputs , output this.
  2. using model, i.e. getting predictions fixed internal coefficients.

for part 1, you've decided normalize data. neural net works on normalized data. have trained neural net

  • on inputs fx(x) rather x, fx transform used matrix of original inputs produce normalized inputs.
  • on outputs fy(y) rather y, fy transform applied vector of outputs normalized outputs.

in terms of original inputs , outputs trained machine looks this:

  • apply normalization function fx inputs normalized inputs fx(x).
  • run neural net normalized inputs produce normalized outputs fy(y).
  • apply denormalization function fy-1 normalized outputs fy(y) y.

note fx(x) , fy, , hence fy-1, defined on training set.

so in r might write training data , normalize it, first 100 rows

tx <- x[1:100,] ntx <- normalizedata(tx, type='0_1') ty <- y[1:100] nty <- normalizedata(ty, type='0_1') 

and denormalize predicted results

pred.y <- denormalizedata(pred.ny, getnormparameters(nty))                                                        # nty (or ny) not nx here 

the slight concern have i'd prefer normalize features used in prediction using same transform fx used training, looking @ rsnns documentation facility doesn't appear present (it easy write yourself, however). ok normalize prediction features using whole x matrix, i.e. including training data. (i can see might preferable use default, normalization z-score rsnns provides rather "0_1" choice have used.)


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -