How to separate features and target (numeric values) in a tabular text datastore to import into Deep Network Design?
Show older comments
Hello everyone, I have the following problem: I imported a csv file with numerical data containing the features and the target into a tabular text datastore, however, to import into Deep Network Design this tabular text datastore needs to contain separate features and target. I have no idea how to do this, can someone give me a hand?
For example, my csv file has 500 rows 10 features and the target.
Thank you very much!
Answers (1)
yanqi liu
on 3 Dec 2021
0 votes
yes,sir,may be choose the data to X and Y,such as
% 500 rows 10 features and the target.
X = Data(:, 1:10); % 10 features
Y = Data(:, end); % target
may be upload some data mat to do analysis
4 Comments
paulo silva
on 3 Dec 2021
Edited: paulo silva
on 3 Dec 2021
yanqi liu
on 4 Dec 2021
yes,sir,may be use cell to rerange data,such as
clc; clear all; close all;
% 500 rows 10 features and the target.
Data = rand(500, 10);
Data(:, 11) = randi([1,2],500,1);
X = Data(:, 1:10); % 10 features
Y = Data(:, end); % target:1、2
% make data
XTrain = [];
for i = 1 : size(X, 1)
xi = X(i,:)';
XTrain{i,1} = xi;
end
YTrain = categorical(Y);
% make net
layers = [ ...
sequenceInputLayer(10)
lstmLayer(5,'OutputMode','last')
fullyConnectedLayer(2)
softmaxLayer
classificationLayer];
options = trainingOptions('adam', ...
'ExecutionEnvironment','cpu', ...
'MaxEpochs',100, ...
'MiniBatchSize',5, ...
'GradientThreshold',1, ...
'Verbose',false, ...
'Plots','training-progress');
net = trainNetwork(XTrain,YTrain,layers,options);
paulo silva
on 4 Dec 2021
Edited: paulo silva
on 8 Dec 2021
Olawale
on 9 Mar 2024
Hello Paulo, can you please explain the code ? seem this might solve the issue i am having too..
thank you
Categories
Find more on Preprocess Data for Deep Neural Networks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!