How can I convert a data set of doubles into a cell arrays?
2 views (last 30 days)
Show older comments
I'm starting using Matlab for machine learning and I have a data set of doubles with structure:
6x70117 double
And need to convert it into a:
6x70117 cell
to be able to train the DNN network because I'm receiving this error:
Invalid training data. For sequence-to-one networks, training data must be cell arrays
I've been trying with some loops but always distort the structure of the data set. Is there any other functional way to do this?
Thank you in advance
6 Comments
Amanjit Dulai
on 27 Feb 2023
The reason for using cell arrays is if you are training on multiple time series. For example, if you were trying to train a model to predict voltage from current for a machine, and you have data recorded from multiple different machines, you would use one cell for each time series from each machine. But it sounds like you only have one time series, in which case you should be able to train without a cell array.
Also, the error you received about "sequence-to-one" suggests your network might not be configured for the right problem. "Sequence-to-one" problems are where the input is a sequence but the output is not (for example, classifying an entire sequence is a sequence-to-one problem).
The code below shows how to train an LSTM for a simple sequence to sequence problem on a single time series:
[X, T] = maglev_dataset;
X = cell2mat(X);
T = cell2mat(T);
trainingFraction = 0.8;
validationFraction = 0.1;
numTimeSteps = size(X,2);
numTrain = floor(numTimeSteps*trainingFraction);
numValidation = floor(numTimeSteps*validationFraction);
numTest = numTimeSteps - numTrain - numValidation;
XTrain = X(:, 1:numTrain);
TTrain = T(:, 1:numTrain);
XValidation = X(:, (numTrain + 1):(numTrain + numValidation));
TValidation = T(:, (numTrain + 1):(numTrain + numValidation));
XTest = X(:, (numTrain + numValidation + 1):end);
TTest = T(:, (numTrain + numValidation + 1):end);
layers = [
sequenceInputLayer(1)
lstmLayer(20)
lstmLayer(20)
lstmLayer(20)
fullyConnectedLayer(1)
regressionLayer
];
options = trainingOptions('adam', ...
'MaxEpochs', 1000, ...
'ValidationData', {XValidation, TValidation}, ...
'Plots', 'training-progress');
net = trainNetwork(XTrain, TTrain, layers, options);
YTest = predict(net, XTest);
rmse = sqrt(mean((TTest - YTest).^2));
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!