Invalid training data. Predictors must be a numeric array, a datastore, or a table. For networks with sequence input, predictors can also be a cell array of sequences.

10 Ansichten (letzte 30 Tage)
cvp = cvpartition(data.Var4,"Holdout",0.3);
dataTrain = data(training(cvp),:);
dataValidation = data(test(cvp),:);
%% Traning
%preprocess data
documentsTrain = preprocessText(dataTrain.Var3); %diagnosis
%%3 categoreis will be trained.
TTrain = categorical(dataTrain.Var4); % result
classNames = unique(TTrain);
numObservations = numel(TTrain);%60
%% validation
documentsValidation = preprocessText(dataValidation.Var3); %diagnosis
TValidation = categorical(dataValidation.Var4);% result
enc = wordEncoding(documentsTrain);
numWords = enc.NumWords;
XTrain = doc2sequence(enc,documentsTrain);
XValidation = doc2sequence(enc,documentsValidation);
embeddingDimension = 100;
ngramLengths = [2 3 4 5];
numFilters = 200;
minLength = min(doclength(documentsTrain));
layers = [
sequenceInputLayer(1,MinLength=minLength)
wordEmbeddingLayer(embeddingDimension,numWords,Name="numwords")];
lgraph = layerGraph(layers);
numBlocks = numel(ngramLengths);
for j = 1:numBlocks
N = ngramLengths(j);
block = [
convolution1dLayer(N,numFilters,Name="conv"+N,Padding="same")
batchNormalizationLayer(Name="bn"+N)
reluLayer(Name="soft"+N)
dropoutLayer(0.2,Name="drop"+N)
globalMaxPooling1dLayer(Name="max"+N)];
lgraph = addLayers(lgraph,block);
lgraph = connectLayers(lgraph,"numwords","conv"+N);
end
numClasses = numel(classNames);
layers = [
concatenationLayer(1,numBlocks,Name="cat")
fullyConnectedLayer(numClasses,Name="fc")
softmaxLayer(Name="soft")
classificationLayer(Name="classification")];
lgraph = addLayers(lgraph,layers);
for j = 1:numBlocks
N = ngramLengths(j);
lgraph = connectLayers(lgraph,"max"+N,"cat/in"+j);
end
figure
plot(lgraph)
title("New")
options = trainingOptions("adam", ...
MiniBatchSize=128, ...
ValidationData={XValidation,TValidation}, ...
OutputNetwork="best-validation-loss", ...
Plots="training-progress", ...
Verbose=false);
net = trainNetwork (TTrain,XTrain,lgraph,options);

Antworten (1)

Prasanna
Prasanna am 10 Dez. 2024
Hi Neeta,
The error message you are getting indicates training data provided to the ‘trainNetwork’ function is not in the expected format. Specifically, the predictors (input data) must be a numeric array, a datastore, or a table. Some steps to debug and resolve the issue are:
  • Check the input data format and ensure that the ‘XTrain’ variable is a cell array of sequences. Each element of the cell array should be a numeric vector representing the sequence for a single observation.
  • Correct the ‘trainNetwork’ function call in your script. The ‘trainNetwork’ function expects the input data (predictors) to be the first argument, followed by the target data (responses). In your code, you have swapped the order. The correct order is ‘trainNetwork(XTrain, TTrain, lgraph, options)’.
Also, ensure that the preprocessing steps, such as ‘preprocessText’ and ‘doc2sequence’, correctly transform the text data into sequences that can be input into the network. By following these steps and ensuring the correct data format and function usage, you should be able to resolve the error and successfully train your network. For more information regarding the error, refer the following documentations:
Hope this helps!

Kategorien

Mehr zu Deep Learning Toolbox finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by