Invalid validation data table. For networks with feature input, predictors must be numeric arrays, where each variable of the table corresponds to one feature.
    8 views (last 30 days)
  
       Show older comments
    
Hello, I am new to matlab. I want to ask what to do if there is an invalid validation data table error. This is my code
filename = "Data1.txt";
tbl = readtable(filename,'TextType','String');
labelName = "output";
tbl = convertvars(tbl,labelName,'categorical');
head(tbl)
categoricalInputNames = ["class" "fractaldimension"];
tbl = convertvars(tbl,categoricalInputNames,'categorical');
for i = 1:numel(categoricalInputNames)
    name = categoricalInputNames(i);
    oh = onehotencode(tbl(:,name));
    tbl = addvars(tbl,oh,'After',name);
    tbl(:,name) = [];
end
tbl = splitvars(tbl);
head(tbl)
classNames = categories(tbl{:,labelName});
numObservations = size(tbl,1);
numObservationsTrain = floor(0.7*numObservations);
numObservationsValidation = floor(0.15*numObservations);
numObservationsTest = numObservations - numObservationsTrain - numObservationsValidation;
idx = randperm(numObservations);
idxTrain = idx(1:numObservationsTrain);
idxValidation = idx(numObservationsTrain+1:numObservationsTrain+numObservationsValidation);
idxTest = idx(numObservationsTrain+numObservationsValidation+1:end);
tblTrain = tbl(idxTrain,:);
tblValidation = tbl(idxValidation,:);
tblTest = tbl(idxTest,:);
numFeatures = size(tbl,2) - 1;
numClasses = numel(classNames);
layers = [
    featureInputLayer(numFeatures,'Normalization', 'zscore')
    fullyConnectedLayer(83)
    batchNormalizationLayer
    reluLayer
    fullyConnectedLayer(numClasses)
    softmaxLayer
    classificationLayer];
 miniBatchSize = 16;
options = trainingOptions('adam', ...
    'MiniBatchSize',miniBatchSize, ...
    'Shuffle','every-epoch', ...
    'ValidationData',tblValidation, ...
    'Plots','training-progress', ...
    'Verbose',false);
net = trainNetwork(tblTrain,labelName,layers,options);
Invalid validation data table. For networks with feature input, predictors must be numeric arrays, where each
variable of the table corresponds to one feature.
0 Comments
Answers (1)
  Rohit
    
 on 23 Mar 2023
        Hi Adib,
As mentioned in this documentation: https://www.mathworks.com/help/deeplearning/ref/trainingoptions.html , you need to specify the validation data as a datastore, table, or the cell array {predictors,responses}, where predictors contains the validation predictors and responses contains the validation responses.
So, you need to modify code as shown below to get rid of error and start the training.
options = trainingOptions('adam', ...
    'MiniBatchSize',miniBatchSize, ...
    'Shuffle','every-epoch', ...
    'ValidationData',{tblValidation,tblValidation(:,labelName)} ,... % passing validation date as cell array of predictors and responses
    'Plots','training-progress', ...
    'Verbose',false);
0 Comments
See Also
Categories
				Find more on Deep Learning Toolbox 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!
