3

1

I have a time-series data for 3 classes (each class is 35 second) as I extract each 1 second for 95 feature extracting so my final data has shape (105,95) (rows for time and column for feature).

I am currently building a 1D-CNN model for classification 3 class. But I got stuck as first layer of Conv1D. I have learnt that the input_shape of Convd1D is (batch_size, new_step, input_dim) but **honestly I dont know what exactly what each element mean and how can I modify (reshape) my input data into Conv1D layer shape?**

And one more question, I know that CNN required fixed input size. But I split my data into train and validation data as k parameter = 5, mean that my data will become: Train = (84,95) and Validation = (21,95). So with the same model how can we train and validate data with difference size?

I just start to learn about CNN but still not know how Conv1D operate?

I am appreciate your help.

Thank you very much.

Hear is my code (Which still get error because of first Conv1D input_shape):

```
X = dataset[:, 0:95].astype(float)
Y = dataset[:, 95].astype(int)
# Encode class values as integers
encoder = LabelEncoder()
encoder.fit(Y)
encoder_Y = encoder.transform(Y)
y = np_utils.to_categorical(encoder_Y)
acc_per_fold = []
loss_per_fold = []
fold_no = 1
kfold = KFold(n_splits = 5, shuffle = True)
for train, test in kfold.split(X,y):
model = Sequential()
model.add(Conv1D(100, 3, activation = 'relu', input_shape = (I really dont know what to put in here??))
model.add(Conv1D(100, 3, activation = 'relu'))
model.add(MaxPooling1D(3))
model.add(Conv1D(150, 3, activation = 'relu'))
model.add(Conv1D(150, 3, activation = 'relu'))
model.add(GlobalAveragePooling1D())
model.add(Dense(3, activation = 'softmax'))
model.compile(loss = 'categorical_crossentropy', optimizer = 'adam', metrics = ['accuracy'])
#model.summary()
print('------------------------------------------------------------------------------')
print(f'Training for {fold_no}...')
history = model.fit(X[train], y[train], batch_size = 7, epochs = 150, verbose = 1)
scores = model.evaluate(X[test], y[test], verbose = 0)
print(f'Score for fold {fold_no}: {model.metrics_names[0]} of {scores[0]}; {model.metrics_names[1]} of {scores[1]*100}%')
acc_per_fold.append(scores[1] * 100)
loss_per_fold.append(scores[0])
# Increase fold number
fold_no = fold_no + 1
```

First of all, thank you for answer my question. Say if I am wrong but I think that input=shape of Conv1D is a 2D shape matrix so that we can aplly filter on that input. Because of that I think the input shape should be (84,95) as Train data and (21,95) as Validation Data. – Q.H.Chu – 2020-07-07T10:05:24.973

Convolution will not happen across instances. It happens on instances individually. I assumed the problem as univariate. So, it will be a 1-D Image and 1-D convolution(For analogy). The kernel will slide in 1-D. Read the link. It has explained most of the stuff – 10xAI – 2020-07-07T10:26:38.890