I am a beginner in machine learning. Although, this question is similar to 1, 2, 3, but I am really confused in selecting the input shape for my data. I am using 1-D CNN on time series data. The dimension of data is (6400, 4). There are 4 features (columns) out of which one is target variable. After splitting:
dim(xtrain) -> 5000, 3
dim(ytrain) -> 5000, 1
dim(xtest) -> 1400, 3
dim(ytest) -> 1400, 1
I am confused in selecting the input shape for CNN. This is what I have tried (I have kept input shape = c(3, 1)):
model = keras_model_sequential() %>%
layer_conv_1d(filters = 64, kernel_size = 2,
input_shape = c(3, 1), activation = "relu") %>%
layer_max_pooling_1d(pool_size = 2) %>%
layer_flatten() %>%
layer_dense(units = 32, activation = "relu") %>%
layer_dropout(rate = 0.2) %>%
layer_dense(units = 1, activation = "linear")
xtrain <- as.matrix(train[, c(1, 2, 3)])
ytrain <- as.matrix(train[, c(4)])
xtest = as.matrix(test[, c(1, 2, 3)])
ytest = as.matrix(test[, c(4)])
# Transforming 2-D matrix into 3-D matrix
xtrain = array(xtrain, dim = c(nrow(xtrain), 3, 1))
xtest = array(xtest, dim = c(nrow(xtest), 3, 1))
# fitting model
model %>% fit(xtrain, ytrain, epochs = 50, batch_size = 128, verbose = 1, validation_split = 0.20)
This executes well, but I am not sure whether it is correct or not. Please tell if this correct way to set the input shape.