Clear Filters
Clear Filters

How to import csv deep learning dataset with labels to matlab?

8 views (last 30 days)
Hello everyone,
I am trying to train a fully connected deep learning model.
I have my data set in a csv file so that each row represents a different signal.
The first 56 coloums represents the signal and the 2 last coloums represents the labels for the signals (there are two labels).
How can I import the cvs file in a way that i will be able to train a deep learning network with it?

Accepted Answer

yanqi liu
yanqi liu on 7 Mar 2022
yes,sir,may be read csv and reshape the data(:,1:56) into 4-D as train_input,data(:, 57:58) make to label vector as train_output
if possible,may be upload your csv to analysis
  3 Comments
yanqi liu
yanqi liu on 10 Mar 2022
yes,sir,now we can use
data = load('Train Data.csv');
% make X and Y
X = data(:, 10 : 65);
Y = data(:, 66 : 67);
[~, Y] = max(Y');
X = X';
Y = Y';
% make cnn
num_class = length(unique(Y));
% make data shuffle
rand('seed', 0)
ind = randperm(size(X, 2));
X = X(:,ind);
Y = Y(ind);
Y = categorical(Y);
% Split Data
rate = 0.8;
ind_split = round(length(Y)*rate);
train_X = X(:,1:ind_split);
train_Y = Y(1:ind_split);
val_X = X(:,ind_split+1:end);
val_Y = Y(ind_split+1:end);
% Data Batch
XTrain=(reshape(train_X, [size(X,1),1,1,size(train_X,2)]));
XVal=(reshape(val_X', [size(X,1),1,1,size(val_X,2)]));
% CNN
layers = [imageInputLayer([size(X,1) 1 1])
convolution2dLayer([30 1],3,'Stride',1)
dropoutLayer
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2,'Padding',[0 0 0 1])
dropoutLayer
fullyConnectedLayer(num_class)
softmaxLayer
classificationLayer];
% Specify training options.
opts = trainingOptions('adam', ...
'MaxEpochs',200, ...
'Shuffle','every-epoch', ...
'Plots','training-progress', ...
'Verbose',false, ...
'ValidationData',{XVal,val_Y},...
'ExecutionEnvironment', 'cpu', ...
'ValidationPatience',Inf);
% Train
yc = categorical(train_Y);
net1 = trainNetwork(XTrain,yc,layers,opts);
% Test
miniBatchSize = 27;
YPred = classify(net1,XVal, ...
'MiniBatchSize',miniBatchSize,...
'ExecutionEnvironment', 'cpu');
acc = mean(YPred(:) == val_Y(:))
figure
t = confusionchart(val_Y(:),YPred(:));
rami dishlo
rami dishlo on 15 Mar 2022
Made some tweaking to make it all work but you really helped me.
Thank you

Sign in to comment.

More Answers (0)

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!