I am trying to use CNN on multivariate time series instead the most common usage on images. The number of features is between 90 and 120, depending on which I need to consider and experiment with. This is my code
scaler = StandardScaler()
X_train_s = scaler.fit_transform(X_train)
X_test_s = scaler.transform(X_test)
X_train_s = X_train_s.reshape((X_train_s.shape[0], X_train_s.shape[1],1))
X_test_s = X_test_s.reshape((X_test_s.shape[0], X_test_s.shape[1],1))
batch_size = 1024
length = 120
n_features = X_train_s.shape[1]
generator = TimeseriesGenerator(X_train_s, pd.DataFrame.to_numpy(Y_train[['TARGET_KEEP_LONG',
'TARGET_KEEP_SHORT']]),
length=length,
batch_size=batch_size)
validation_generator = TimeseriesGenerator(X_test_s, pd.DataFrame.to_numpy(Y_test[['TARGET_KEEP_LONG', 'TARGET_KEEP_SHORT']]), length=length, batch_size=batch_size)
early_stop = EarlyStopping(monitor = 'val_accuracy', mode = 'max', verbose = 1, patience = 20)
CNN_model = Sequential()
model.add(
Conv2D(
filters=64,
kernel_size=(1, 5),
strides=1,
activation="relu",
padding="valid",
input_shape=(length, n_features, 1),
use_bias=True,
)
)
model.add(MaxPooling2D(pool_size=(1, 2)))
model.add(
Conv2D(
filters=64,
kernel_size=(1, 5),
strides=1,
activation="relu",
padding="valid",
use_bias=True,
)
)
[... code continuation ...]
In other words, I take the features as one dimension and a certain number of rows as the other dimension. But I get this error
"ValueError: Input 0 of layer "conv2d_5" is incompatible with the layer: expected min_ndim=4, found ndim=2. Full shape received: (None, 2)"
that is referred to the first CNN layer.
from Input 0 of layer "conv2d_5" is incompatible with the layer: expected min_ndim=4, found ndim=2. Full shape received: (None, 2)
No comments:
Post a Comment