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

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?

 채택된 답변

yanqi liu
yanqi liu 2022년 3월 7일

0 개 추천

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

yes this is the csv file, data is from 10 - 65 and labels are from 66 - 67.
if you can share with me an exemple code i will really appriciate it.
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(:));
Made some tweaking to make it all work but you really helped me.
Thank you

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2022년 3월 5일

댓글:

2022년 3월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by