I'm trying to predict the next value based on the previous value for my cnn+lstm model, but I get the overall average for each prediction. My data consists of heatmap images of a neighborhood (features) for twenty weeks with the number of crimes (labels) for each week. I tried changing the number of epochs, changing the batch size, and changing number of parameters in my model. Below is my model.
# MODEL
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D
from keras.layers import Activation, Dropout, Flatten, Dense
def baseline_model():
#create model
model = Sequential()
model.add(
TimeDistributed(
Conv2D(16, (3, 3), strides=(2,2), data_format='channels_last', activation='relu'),
input_shape=(1,256, 256,3)# looking back 1 image
)
)
model.add(
TimeDistributed(
MaxPooling2D(pool_size=(2, 2))
)
)
model.add(
TimeDistributed(
Conv2D(16, (3, 3), activation='relu'),
)
)
model.add(
TimeDistributed(
MaxPooling2D(pool_size=(2, 2))
)
)
model.add(
TimeDistributed(
Conv2D(32, (3, 3),activation='relu'),
)
)
model.add(
TimeDistributed(
MaxPooling2D(pool_size=(2, 2))
)
)
model.add(
TimeDistributed(
Flatten()
)
)
model.add(
LSTM(4, return_sequences=True)
)
model.add(Dense(2, activation='relu'))
model.add(Flatten())
model.add(Dense((1), activation='linear'))
#Compile model
model.compile(loss='mean_squared_error', optimizer='adam')
return model
# evaluate model
estimator = KerasRegressor(build_fn=baseline_model, epochs=500, batch_size=1,verbose=0)
kfold = KFold(n_splits=10)
results = cross_val_score(estimator, X, y, cv=kfold)
print("Baseline: %.2f (%.2f) MSE" % (results.mean(), results.std()))
Baseline: -16.57 (19.04) MSE
estimator.fit(X, y)
prediction = estimator.predict(X)
print(y)
print(prediction)
[[ 4]
[ 7]
[ 7]
[ 6]
[13]
[11]
[10]
[ 4]
[11]
[10]
[ 6]
[ 7]
[ 2]
[17]
[14]
[ 9]
[ 8]
[ 8]
[ 4]
[ 8]]
[8.324332 8.324332 8.324332 8.324332 8.324332 8.324332 8.324332 8.324332
8.324332 8.324332 8.324332 8.324332 8.324332 8.324332 8.324332 8.324332
8.324332 8.324332 8.324332 8.324332]