Invalid training data table

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

 Accepted Answer

Abhishek Gupta
Abhishek Gupta on 16 Dec 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 Comments

Thank you for you help, it realy helped me alot,
Now I have another question regarding data fusion, what if my data is not only a recorded in the same data type, for instnace if I have a image data set and cvs recorde and video or auido files. can I use fusion data to intergarate all these resources to enhance prediction and accuracy.
A straightforward way to improve the predictions using multiple data-types would be as follows: -
  1. Train a network separately for each data-type. You have an image and numeric data-types (let say), then train a CNN for image dataset and a feedforward network for the numeric dataset. Note - output of the CNN and feedforward network would be the same.
  2. After training, you will have two predictions for the same input with two different data-type. Use these two predictions to make your forecast better (define some criteria).
Another slightly complicated way would be: -
  1. Create a network for each data-type to convert your input (image or numeric data) into a feature vector (basically the network's output).
  2. Combine the feature vectors from the different data-type into one vector (concatenate the vectors). This combined vector will contain the input features from different data-type.
  3. Use the combined feature vector as your input and train another network to make your final predictions.
Thank you for your help, I implemented the first soluation and it works fine, my question about the second method, is there any working example for how to convert the data to a feature vector ?
i have data in excle file and i want to classify it with deep laering but i got error in featureinput layer?
What type of data ? I mean, is it numerical values or text ?
numeric
Hi Hany!
I have the same problem (Invalid training data table), can you teach me how to fix it?
Thank you

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!