1D CNN for time series data

I am writing for creating a 1d CNN model in which the 'X' is input matrix of 123*6 matrix and 'Y' is the output matrix of 123*1. CNN model has 7 layers including 3 convolution layer 2 maxpooling layer and 2 fully connected layer. The first convolution kernel is 6*1 size and stride is 6. ReLu is the activation funtion. Optimizer is adam. and number of iteration (epoochs) is 200. The sequence of cnn model is input layer then first convoultion layer the max pooling layer then second convolution layer then maxpooling layer. Then third convolution layer. Then two fully connected layers then output.
%% Load the data
load('all_features.mat')
d=features;
X=features(:,1:6);
Y=features(:,7);
%%
% Split data into training and validation sets
numObservations = size(X,1);
idx = randperm(numObservations);
numTrain = round(0.8 * numObservations);
idxTrain = idx(1:numTrain);
idxValidation = idx(numTrain+1:end);
XTrain = X(idxTrain,:);
YTrain = Y(idxTrain,:);
XValidation = X(idxValidation,:);
YValidation = Y(idxValidation,:);
% Define model architecture
layers = [ sequenceInputLayer(6,'MinLength',123) convolution1dLayer(6,6) reluLayer maxPooling1dLayer(6,'Stride',6) convolution1dLayer(6,6) reluLayer maxPooling1dLayer(6,'Stride',6) convolution1dLayer(6,6) reluLayer fullyConnectedLayer(6) fullyConnectedLayer(1) regressionLayer];
% Set training options
options = trainingOptions('adam', ...
'MaxEpochs',200, ...
'ValidationData',{XValidation,YValidation}, ...
'Verbose',false, ...
'Plots','training-progress');
% Train model
XTrain = padarray(XTrain,[0 123-size(XTrain,2)],'post');
XValidation = padarray(XValidation,[0 123-size(XValidation,2)],'post');
cnn = trainNetwork(XTrain,YTrain,layers,options);
YPred = predict(cnn,XTest);
kindly help me to debug the issue.

1 Comment

What is exactly the issue? Please share any error message or screenshot.
From the understanding of dataset information and the CNN model shared by you, it seems you are trying to solve a problem of time-series regression. You can also go through below documnetation pages for more information.

Sign in to comment.

Answers (0)

Categories

Asked:

on 16 Dec 2022

Commented:

on 5 Jan 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!