How to import csv deep learning dataset with labels to matlab?
14 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
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
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(:));
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Deep Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!