【问题标题】:Normalization of data in continuous neural network training in RR中连续神经网络训练中数据的归一化
【发布时间】:2018-06-29 21:32:10
【问题描述】:

随着我的输入不断涌现,我想对我的神经网络进行持续训练。但是,当我获得新数据时,标准化值会随着时间而变化。假设我及时得到:

df <- "Factor1 Factor2 Factor3 Response
        10      10000   0.4     99
        15      10200   0       88
        11      9200    1       99
        13      10300   0.3     120"
df <- read.table(text=df, header=TRUE)

normalize <- function(x) {
    return ((x - min(x)) / (max(x) - min(x)))
}

dfNorm <- as.data.frame(lapply(df, normalize))

### Keep old normalized values
dfNormOld <- dfNorm 

library(neuralnet)
nn <- neuralnet(Response~Factor1+Factor2+Factor3, data=dfNorm, hidden=c(3,4), 
    linear.output=FALSE, threshold=0.10,  lifesign="full", stepmax=20000)

那么,随着时间二的到来:

df2 <- "Factor1 Factor2 Factor3 Response
        12      10100   0.2     101
        14      10900   -0.7    108
        11      9800    0.8     120
        11      10300   0.3     113"

df2 <- read.table(text=df2, header=TRUE)

### Bind all-time data
df <- rbind(df2, df)

### Normalize all-time data in one shot
dfNorm <- as.data.frame(lapply(df, normalize))

### Continue training the network with most recent data
library(neuralnet)
Wei <- nn$weights
nn <- neuralnet(Response~Factor1+Factor2+Factor3, data=df[1:nrow(df2),], hidden=c(3,4), 
    linear.output=FALSE, threshold=0.10,  lifesign="full", stepmax=20000, startweights = Wei)

这将是我随着时间的推移训练它的方式。但是,我想知道是否有任何优雅的方法可以减少这种持续训练的偏差,因为标准化值会随着时间的推移不可避免地发生变化。在这里,我假设非标准化值可能存在偏差。

【问题讨论】:

  • 如果非归一化值有偏差,归一化值也会有偏差。您不会通过更改值的比例来消除偏见。
  • 一种解决方案可能是对每个变量使用通用的最小值和最大值,并始终使用它们进行标准化。它可能接近您期望的最大和最小测量值(?)。当然,这取决于变量的性质。

标签: r neural-network normalization training-data


【解决方案1】:

您可以使用此代码:

normalize <- function(x,min1,max1,row1) {
     if(row1>0)
        x[1:row1,] = (x[1:row1,]*(max1-min1))+min1
     return ((x - min(x)) / (max(x) - min(x)))
 }

past_min = rep(0,dim(df)[2])
past_max = rep(0,dim(df)[2])
rowCount = 0

while(1){
df = mapply(normalize, x=df, min1 = past_min, max1 = past_max,row1 = rep(rowCount,dim(df)[2]))
nn <- neuralnet(Response~Factor1+Factor2+Factor3, data=dfNorm, hidden=c(3,4), 
                    linear.output=FALSE, threshold=0.10,  lifesign="full", stepmax=20000)

past_min = as.data.frame(lapply(df, min))
past_max = as.data.frame(lapply(df, max))
rowCount = dim(df)[1]

df2 <- read.table(text=df2, header=TRUE)
df <- rbind(df2, df)
}

【讨论】:

    猜你喜欢
    • 2017-01-27
    • 2012-03-24
    • 1970-01-01
    • 2014-05-15
    • 2018-01-27
    • 2019-01-14
    • 2013-03-28
    • 2011-04-07
    • 1970-01-01
    相关资源
    最近更新 更多