Training with trainNetwork failed. The value of 'ValidationData' is invalid. The datastore used for 'ValidationData' must return a table or cell array 2 columns.with at least

조회 수: 4 (최근 30일)
Hello, I want to do classification with LSTM using Deep Network Designer. But my data consists of features in .xlsx format. I created a datastore with the code given below and did the necessary operations. After importing the data, when I click on the Training tab in the deep network designer section, "Training with trainNetwork failed. The value of 'ValidationData' is invalid. The datastore used for 'ValidationData' must return a table or cell array 2 columns with at least" error message. Can you help.
  댓글 수: 3
Matt J
Matt J 2024년 4월 17일
It is also preferred to copy/past your code rather than share a screenshot.
Yes, otherwise we cannot copy/paste it to demonstrate solutions.
Atakan Öztürk
Atakan Öztürk 2024년 4월 18일
% Load data
[numData, txtData, raw] = xlsread('veriseti2.xlsx');
% Separating numeric and text data
numericData = numData(:, 1:5); % The first 5 columns represent numeric data
textData = raw(:, 6); % Column 6 represents text data
% Convert text data to categorical variables
categoricalData = categorical(textData);
% Convert categorical variables to numeric values
encodedData = grp2idx(categoricalData);
% Separating input data and output labels
inputData = numericData; % Numeric properties
outputLabels = encodedData; % Converted categorical labels
% Create a partition that splits the data for training and validation
cv = cvpartition(size(numericData, 1), 'HoldOut', 0.2); % 80% training, 20% validation
% Get indices of training and validation data
trainingIdx = cv.training;
% Separate training and validation data
TrainingData = inputData(trainingIdx, :);
ValidationData = inputData(~trainingIdx, :);
TrainingLabels = outputLabels(trainingIdx, :);
ValidationLabels = outputLabels(~trainingIdx, :);
% Convert training and validation data to datastore
dstrain = arrayDatastore(TrainingData); % Training data and tags
dsvalidation = arrayDatastore(ValidationData); % Validation data and tags

댓글을 달려면 로그인하십시오.

채택된 답변

Cris LaPierre
Cris LaPierre 2024년 4월 18일
Because the input must be a datastore, you need to format your input so that your five features are a column vector. Here's code that I wrote that got the training to work in the Deep Network Designer
% Load data
data = readtable('veriseti2.xlsx');
% Format data
data = convertvars(data,"Var6",'categorical');
trainingData = mergevars(data,1:5);
trainingData.Properties.VariableNames = ["Predictors","Response"];
trainingData.Predictors = rowfun(@transpose,trainingData,"InputVariables","Predictors","OutputFormat","cell");
% Create a partition that splits the data for training and validation
cv = cvpartition(height(trainingData), 'HoldOut', 0.2); % 80% training, 20% validation
% Get indices of training and validation data
trainingIdx = cv.training;
validationIdx = cv.test;
% Separate training and validation data
TrainingData = trainingData(trainingIdx, :);
ValidationData = trainingData(validationIdx, :);
% Convert training and validation data to datastore
dstrain = arrayDatastore(TrainingData,'OutputType','same'); % Training data and tags
dsvalidation = arrayDatastore(ValidationData,'OutputType','same'); % Validation data and tags
I find that, at least with your data set, having to work with datastores makes it more difficult. I would reocmmend exporting your network using the Generate Network Code without Parameters and set up your training programmatically. Here's what that might look like.
% Create a partition that splits the data for training and validation
cv = cvpartition(height(data), 'HoldOut', 0.2); % 80% training, 20% validation
% Get indices of training and validation data
trainingIdx = cv.training;
validationIdx = cv.test;
% Separate training and validation data
TrainingData = data(trainingIdx, :);
ValidationData = data(validationIdx, :);
layers = [
featureInputLayer(5,'Normalization', 'zscore')
lstmLayer(128,"Name","lstm")
dropoutLayer(0.5,"Name","dropout")
fullyConnectedLayer(4,"Name","fc")
softmaxLayer("Name","softmax")
classificationLayer("Name","classoutput")];
options = trainingOptions('adam', ...
'MiniBatchSize',128, ...
'Shuffle','every-epoch', ...
'ValidationData',ValidationData, ...
'Plots','training-progress', ...
'Verbose',false);
net = trainNetwork(TrainingData,layers,options)
  댓글 수: 1
Cris LaPierre
Cris LaPierre 2024년 4월 18일
If you do want to train in the Deep Network Designer, if you add a flatten layer, then your formatting of the input could just be
data = readtable('veriseti2.xlsx');
data = convertvars(data,"Var6",'categorical');
data = mergevars(data,1:5);

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Catalytic
Catalytic 2024년 4월 17일
편집: Catalytic 2024년 4월 17일
Your ValidationData is just an arrayDatastore of input data. The error message has told you that it must include input and output pairs, and that these must be in cell array or table form.

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by