Invalid training data table

6 次查看(过去 30 天)
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')
fullyConnectedLayer(50)
batchNormalizationLayer
reluLayer
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer];
%Training Options
miniBatchSize = 16;
options = trainingOptions('adam', ...
'MiniBatchSize',miniBatchSize, ...
'Shuffle','every-epoch', ...
'ValidationData',tblValidation, ...
'Plots','training-progress', ...
'Verbose',false);
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
Hi,
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 个)

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by