Invalid validation data table. For networks with feature input, predictors must be numeric arrays, where each variable of the table corresponds to one feature.
조회 수: 2 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Rohit
2023년 3월 23일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Classification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!