我使用迴歸神經網絡(RNN)進行預測,但是對於一些奇怪的原因,它總是輸出1。這裏我用玩具例如作爲解釋這一點:爲什麼RNN總是輸出1
例 考慮尺寸爲(360,5)的矩陣M
,以及包含的rowum的矢量Y
。現在,使用RNN,我想從M
預測Y
。使用rnn
R
包,我訓練模型
library(rnn)
M <- matrix(c(1:1800),ncol=5,byrow = TRUE) # Matrix (say features)
Y <- apply(M,1,sum) # Output equls to row sum of M
mt <- array(c(M),dim=c(NROW(M),1,NCOL(M))) # matrix formatting as [samples, timesteps, features]
yt <- array(c(Y),dim=c(NROW(M),1,NCOL(Y))) # formatting
model <- trainr(X=mt,Y=yt,learningrate=0.5,hidden_dim=10,numepochs=1000) # training
一個奇怪的事情。
接着,我創建具有相同的結構的測試數據集如上述一個爲:
M2 <- matrix(c(1:15),nrow=3,byrow = TRUE)
mt2 <- array(c(M2),dim=c(NROW(M2),1,NCOL(M2)))
predictr(model,mt2)
隨着預測,我總是得到輸出爲1。 什麼可以是用於恆定曆元錯誤的原因和相同的輸出?
UPDATE#1
@Barker提供的答案不適用於我的問題。爲了使它開放,在這裏我通過Dropbox鏈接分享極簡主義數據,如traindata,testadata和我的R
代碼。
數據詳情:列「功率」是響應變量是溫度,溼度的功能,以及功率消耗的前幾天從DAY1到第14天。
normalize_data <- function(x){
normalized = (x-min(x))/(max(x)-min(x))
return(normalized)
}
#read test and train data
traindat <- read.csv(file = "train.csv")
testdat <- read.csv(file = "test.csv")
# column "power" is response variable and remaining are predictors
# predictors in traindata
trainX <- traindat[,1:dim(traindat)[2]-1]
# response of train data
trainY <- traindat$power
# arrange data acc. to RNN as [samples,time steps, features]
tx <- array(as.matrix(trainX), dim=c(NROW(trainX), 1, NCOL(trainX)))
tx <- normalize_data(tx) # normalize data in range of [0,1]
ty <- array(trainY, dim=c(NROW(trainY), 1, NCOL(trainY))) # arrange response acc. to predictors
# train model
model <- trainr(X = tx, Y = ty, learningrate = 0.08, hidden_dim = 6, numepochs = 400)
# predictors in test data
testX <- testdat[,1:dim(testdat)[2]-1]
testX <- normalize_data(testX) # normalize data in range of [0,1]
#testY <- testdat$power
# arrange data acc. to RNN as [samples,time steps, features]
tx2 <- array(as.matrix(testX), dim=c(NROW(testX), 1, NCOL(testX))) # predict
pred <- predictr(model,tx2)
pred
我改變參數learning rate, hidden_dim, numepochs
,但仍或者導致0.9或1.
最簡單的原因是您的學習率太高,或者模型不符合數據。 –
我發現你的數據有問題。首先,數據太小而無法調試。甚至一個線性模型可能會掙扎給予一個訓練數據集16列和37行,但神經網絡?忘掉它。你的數據似乎並不是爲了其他明智的做法,你的每一行的滯後將與先前的行相同,只是移動到一列。 RNN需要按順序輸入數據。最後,爲什麼你使用滯後作爲功能呢? RNN的全部重點是「記憶」方面,它能夠記住先前的數據。如果你反饋的是先前的價值觀,那麼你的網絡就會變得更加複雜。 – Barker
@巴克,我明白你的意思了!但是我仍然面臨着時間序列數據建模acc的問題。 RNN輸入,我已經問過同樣的問題在http://stackoverflow.com/q/42431720/3317829 –