フィルターのクリア

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

8 ビュー (過去 30 日間)
rami dishlo
rami dishlo 2022 年 3 月 5 日
コメント済み: rami dishlo 2022 年 3 月 15 日
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 日
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 件のコメント
yanqi liu
yanqi liu 2022 年 3 月 10 日
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 2022 年 3 月 15 日
Made some tweaking to make it all work but you really helped me.
Thank you

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDeep Learning Toolbox についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by