Problems with shape of Conv1D on Keras
I have some problems with layers construction on Keras. I explain the whole problem:
- I have a feature matrix, with dimensions: 2023 (rows) x 65 (features);
- I tried to build a CNN, with Conv1D as first layer;
My code is:
def cnn_model():
model = Sequential()
model.add(Conv1D(filters=64, kernel_size=3, activation='relu'))
model.add(Dropout(0.25))
model.add(Conv1D(filters=64, kernel_size=3, activation='relu'))
model.add(Dropout(0.25))
model.add(MaxPooling1D(pool_size=2))
model.add(Flatten())
model.add(Dense(64, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='mse', optimizer='adam', metrics=['mse', 'mae'])
model.fit(X, Y, epochs=100, batch_size=64, verbose=0)
model.evaluate(X, Y)
return model
scoring = make_scorer(score_func=pearson)
# evaluate model with standardized dataset
estimation = []
estimation.append(('standardize', StandardScaler()))
estimation.append(('mlp', KerasRegressor(build_fn=cnn_model, epochs=50, batch_size=32, verbose=0)))
pipeline = Pipeline(estimation)
kfold = KFold(n_splits=10, shuffle=True, random_state=1)
results = cross_val_score(pipeline, X, Y, cv=kfold, scoring=scoring)
The problem is that, when it runs, I get the following error:
ValueError: Input 0 of layer sequential_9 is incompatible with the layer: : expected min_ndim=3, found ndim=2. Full shape received: (None, 64)
I really don't know why this error occurs. Probably it's just a problem with parameters passing, I'm quite new on this field. Can you tell me something more? I tried a bunch of things in order to solve this error but every time I get some new errors instead of solving. Thank you all.
Category Data Science