1
$\begingroup$

I would like to use CNN for time-series prediction problem. I have hourly solar irradiance data for 365 days. What I would like to do is training my network with 1 week data and predict next day.

Training Data: Xtrain: Day-1 Hour-1 to Hour-24, Day-2 Hour-1 to Hour-24 ... Day-6 Hour-1 to Hour-24
Ytrain: Day-7 Hour-1 to Hour-24

I have created a new dataset which takes 24 hours of a day in the rows and 7 days in the columns, so it is (8616,7) matrix.

hour-1 day-1, day-2 ... day-7
hour-2 day-1, day-2 ... day-7
.
.
.
hour-24 day-1, day-2 ... day-7

hour-1 day-2, day-3 ... day-8
hour-2 day-2, day-3 ... day-8
.
.
.
hour-24 day-2, day-3 ... day-8
.
.
.
hour-1 day-359, day-360 ... day-365
hour-2 day-359, day-360 ... day-365
.
.
.
hour-24 day-359, day-360 ... day-365

First of all, is this a correct way to create a dataset?

Keras Code:

xtrain = dataset[0:24,0:6] # takes 24 hour for 6 days
ytrain = dataset[24:48,6] # takes 24 hour of 7th day
xtest = dataset[24:48,0:6] # takes 24 hours for 6 days (day2 to day7) to predict day 7
ytest = dataset[24:48,6] 

model = Sequential()
model.add(Conv1D(6,kernel_size=3,activation='relu', input_shape=(24,6))) #input_shape=()
model.add(MaxPooling1D(pool_size=3))
model.add(Conv1D(12,kernel_size=3,activation='relu'))
model.add(MaxPooling1D(pool_size=3))
model.add(Flatten())
model.add(Dense(48,activation='tanh'))
model.add(Dense(24, activation='linear'))

model.compile(loss='mse',
              optimizer=keras.optimizers.Adam(),
              metrics=['mae'])

model.fit(xtrain,ytrain,epochs=1000,verbose=2)

pred_data = model.predict(xtest)

When I run this code, it gives me an error "ValueError: Error when checking input: expected conv1d_15_input to have 3 dimensions, but got array with shape (24, 6)"

I am really not sure what I should give as an input with 3 dimension, and I am also not sure the way a created dataset is a correct approach.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.