Invalid training data table

6 Ansichten (letzte 30 Tage)
Hany Hussein
Hany Hussein am 13 Dez. 2020
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

Akzeptierte Antwort

Abhishek Gupta
Abhishek Gupta am 16 Dez. 2020
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 Kommentare
Asaf Raza
Asaf Raza am 8 Mär. 2021
numeric
Alejandro Herrera
Alejandro Herrera am 8 Okt. 2021
Bearbeitet: Alejandro Herrera am 8 Okt. 2021
Hi Hany!
I have the same problem (Invalid training data table), can you teach me how to fix it?
Thank you

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by