Hello. I am working with the neural network for time series prediction in RStudio. I successfully run the following block of code:
#R data download
dir.create("~/Downloads/jena_climate",recursive = TRUE)
download.file(
"https://s3.amazonaws.com/keras-datasets/jena_climate_2009_2016.csv.zip",
"~/Downloads/jena_climate/jena_climate_2009_2016.csv.zip"
)
unzip("~/Downloads/jena_climate/jena_climate_2009_2016.csv.zip",
exdir="~/Downloads/jena_climate")
library(tibble)
library(readr)
library(ggplot2)
library(keras)
library(tensorflow)
#R import
data_dir<-"~/Downloads/jena_climate"
fname<-file.path(data_dir,"jena_climate_2009_2016.csv")
raw_data<-read_csv(fname)
glimpse(raw_data)
#R data preprocessing
data<-data.matrix(raw_data[,-1])
mean<-apply(data,2,mean)
std<-apply(data,2,sd)
data<-scale(data,center = mean,scale = std)
normalize<-function(x){
return((x-min(x))/(max(x) - min(x)))
}
max<-apply(data,2,max)
min<-apply(data,2,min)
data<-apply(data,2,normalize)
plot(data[1:30000,2 ])
plot(data[30000:50000,2 ])
#R Generators
generator<-function(data,
lookback,
delay,
min_index,
max_index,
shuffle=FALSE,
batch_size=128,
step=6){
if (is.null(max_index))
max_index <- nrow(data) - delay - 1
i <- min_index + lookback
function() {
if (shuffle) {
rows <- sample(c((min_index+lookback):max_index), size = batch_size)
} else {
if (i + batch_size >= max_index)
i <<- min_index + lookback
rows <- c(i:min(i+batch_size-1, max_index))
i <<- i + length(rows)
}
samples <- array(0, dim = c(length(rows),
lookback / step,
dim(data)[[-1]]))
targets <- array(0, dim = c(length(rows)))
for (j in 1:length(rows)) {
indices <- seq(rows[[j]] - lookback, rows[[j]]-1,
length.out = dim(samples)[[2]])
samples[j,,] <- data[indices,]
targets[[j]] <- data[rows[[j]] + delay,2]
}
list(samples, targets)
}
}
lookback<-1440
step<-6
delay<-44
batch_size<-64
train_gen<-generator(data,
lookback = lookback,
delay = delay,
min_index = 1,
max_index = 30000,
shuffle = FALSE,
step=step,
batch_size = batch_size)
Everything goes well until I come to the following block of code:
#R FlattenNN
lookback<-240
step<-1
delay<-44
batch_size<-44
train_gen<-generator(
data,
lookback = lookback,
delay = delay,
min_index = 1,
max_index = 30000,
shuffle = FALSE,
step=step,
batch_size = batch_size)
train_gen_data<-train_gen()
model<-keras_model_sequential() %>%
layer_flatten(input_shape=c(lookback / step, dim(data)[-1])) %>%
layer_dense(units=128,activation="relu") %>%
layer_dense(units=64,activation="relu") %>%
layer_dense(units=1)
summary(model)
model %>% compile(optimizer=optimizer_rmsprop(),
loss="mae")
history<-model %>% fit_generator(train_gen,
steps_per_epoch=500,
epochs=3)
When I start compiling this block of code, in the R console I always see the red stop sign and the text:
Epoch 1/3
1/500 [..............................] - ETA: 0s - loss: 0.0791
And nothing happens. The code running process doesn't come to its end, and I can't do anything in the markdown/console.
I have been waiting for an hour for the code to compile, but nothing has happened.
When I click on the red stop button,the following window opens:
In this case I only have to terminate current Rsession and close the RStudio .
Could you,please, tell me, what is the problem with this block of code? How to solve it?
Thank you for your effort.