How can I convert a data set of doubles into a cell arrays?

3 visualizzazioni (ultimi 30 giorni)
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 Commenti
Manuel Alejandro
Manuel Alejandro il 8 Feb 2023
Dear, thank you for your reply
Originally both, "XTraining" and "YTraining" are doubles with 6x70117, but since for:
[net info] = trainNetwork(XTraining,YTraining,layers,options);
the predictors must be a cell array, when I run it I receive this error:
Invalid training data. For sequence-to-one networks, training data must be cell arrays
So, when I convert XTraining from "double" to "cell", either by using "num2cell" or a loop, I receive then this error:
Error using trainNetwork
Invalid training data. Predictors and responses must have the same number of observations.
Error in HybridDNN5 (line 171)
[net info] = trainNetwork(XTraining,YTraining,layers,options);
The idea of the code is to train a DNN for a regression task with 5 predictors and 1 response.
Amanjit Dulai
Amanjit Dulai il 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));

Accedi per commentare.

Risposte (0)

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by