Invalid training data table

조회 수: 26(최근 30일)
Hany Hussein
Hany Hussein 2020년 12월 13일
편집: Alejandro Herrera 2021년 10월 8일
Dear All,
I'm traing to train a network with numeric data, it reads a covid-19 Patients data such as Age, weight, gender and temprture, these data in csv format, here is my code
%loading file
filename = "Patient_cardio_COVID.csv";
tbl = readtable(filename,'TextType','String','PreserveVariableNames',true) ;
%Convert the labels for prediction to categorical using the convertvars function.
labelName = "active";
tbl = convertvars(tbl,labelName,'categorical');
categoricalInputNames = {'cardio','smoke', 'Body_Temprature'} ;
tbl = convertvars(tbl,categoricalInputNames,'categorical') ;
classNames = categories(tbl{:,labelName}) ;
%Split Data Set into Training and Validation Sets
%Partition the data set into training, validation, and test partitions. Set aside 15% of the data for validation, and 15% for testing.
numObservations = size(tbl,1) ;
%Determine the number of observations for each partition.
numObservationsTrain = floor(0.7*numObservations) ;
numObservationsValidation = floor(0.15*numObservations);
numObservationsTest = numObservations - numObservationsTrain - numObservationsValidation ;
%Create an array of random indices corresponding to the observations and partition it using the partition sizes
idx = randperm(numObservations);
idxTrain = idx(1:numObservationsTrain);
idxValidation = idx(numObservationsTrain+1:numObservationsTrain+numObservationsValidation);
idxTest = idx(numObservationsTrain+numObservationsValidation+1:end);
%Partition the table of data into training, validation, and testing partitions using the indices
tblTrain = tbl(idxTrain,:) ;
head (tblTrain)
tblValidation = tbl(idxValidation,:);
tblTest = tbl(idxTest,:);
%Define Network Architecture
numFeatures = size(tbl,2) - 1 ;
numClasses = numel(classNames) ;
layers = [
featureInputLayer(numFeatures,'Normalization', 'zscore')
%Training Options
miniBatchSize = 16;
options = trainingOptions('adam', ...
'MiniBatchSize',miniBatchSize, ...
'Shuffle','every-epoch', ...
'ValidationData',tblValidation, ...
'Plots','training-progress', ...
net = trainNetwork(tblTrain,labelName,layers,options);
at this stage I got this error messsage
"Invalid training data table. For networks with feature input, predictors must be numeric arrays, where each variable of
the table corresponds to one feature"
Any Advice

채택된 답변

Abhishek Gupta
Abhishek Gupta 2020년 12월 16일
As per my understanding, you are getting the "Invalid training data table" error while training a neural network. It seems like your input data isn't of the numeric type, instead is in the form of categories. Note that the ability to work with categorical variables is not available in Neural Network Toolbox and is supported with Statistics Toolbox.
The possible workaround for this would be to represent your categories as numeric values. For the same, you can follow any of the following approaches: -
  1. Represent each category as an integer
  2. Use 1-of-N encoding.
Referring to the following link for more details: -
  댓글 수: 7
Alejandro Herrera
Alejandro Herrera 2021년 10월 8일
편집: Alejandro Herrera 2021년 10월 8일
Hi Hany!
I have the same problem (Invalid training data table), can you teach me how to fix it?
Thank you

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

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by