Too many input arguments.

clc;
close all;
clear all;
%load train dataset
train=xlsread('trainchanged.csv','A2:AG1000');
class_label=train(:,33);
%exclude eventid,weight from init_table
train_sample=train(:,2:31);
%appending class label
final_train=[train_sample class_label];
x=final_train(:,1:30);
xx=array2table(x);
yy=categorical(final_train(:,end));
%lstm definition
layers = [ ...
sequenceInputLayer(1)
bilstmLayer(100,'OutputMode','last')
fullyConnectedLayer(2)
softmaxLayer
classificationLayer
];
options = trainingOptions('adam', ...
'MaxEpochs',10, ...
'MiniBatchSize', 150, ...
'InitialLearnRate', 0.01, ...
'SequenceLength', 1000, ...
'GradientThreshold', 1, ...
'ExecutionEnvironment',"auto",...
'plots','training-progress', ...
'Verbose',false);
%train the network
net = trainNetwork(xx,yy,layers,options);
how to resolve the error: Too many input arguments.

5 Commenti

Adam Danz
Adam Danz il 10 Gen 2020
Modificato: Adam Danz il 11 Gen 2020
How about you make it easy for us to help you by telling us what line is producing the code. Sharing the entire copy-pasted error message would give us a lot of info, too.
BTW, you know that we cannot run that code, right?
well here is my whole error
Error in study8 (line 38)
net = trainNetwork(xx,yy,layers,options);
Caused by:
Error using trainNetwork>iParseInputArguments (line 274)
Too many input arguments.
i know we can't run the code. i want know if it is due to some logical mistake.
Walter Roberson
Walter Roberson il 11 Gen 2020
Which MATLAB version are you using?
Chandini Govind
Chandini Govind il 11 Gen 2020
2018b
Adam Danz
Adam Danz il 11 Gen 2020
"i know we can't run the code. i want know if it is due to some logical mistake."
@ Chandini Govind , I was able to identify the error because I happen to have r2018b on my laptop. Note that r2019b, the most recent release, does not have the same code for this function and we could not have identified the problem using the current release.
If you would have provided us with inputs, almost any experienced volunteer here could have instantly seen that your first input is a table while you're using numeric syntax. This is why it's almost always helpful to provide inputs that allow us to reproduce the problem.

Accedi per commentare.

 Risposta accettata

Adam Danz
Adam Danz il 11 Gen 2020
Modificato: Adam Danz il 11 Gen 2020
Understand the input options
In your version of Matlab (r2018b) as well as in the current release (r2019b), there are multiple syntax options for this function that allow for various input types:
Your code uses the numeric input syntax
net = trainNetwork(xx,yy,layers,options);
where xx and yy are expected to be numeric arrays.
What does your error tell us?
Your error in r2018b is thrown at line 274 in trainNetwork().
Error using trainNetwork>iParseInputArguments (line 274)
That line is within a conditional statement that indicates that your first input xx is actually a table. As you can see in the image below. If you look at the "table" syntax above, you'll see that it only has 3 inputs.
Solution
Use the right syntax for tables.

9 Commenti

Chandini Govind
Chandini Govind il 12 Gen 2020
Modificato: Adam Danz il 12 Gen 2020
Error in study8 (line 39)
net = trainNetwork(xx,layers,options);
Caused by:
Error using cellfun
Input #2 expected to be a cell array, was double instead.
i'm getting this error(snapshot from workspace).is there any example for handling neural network with table?
".is there any example for handling neural network with table?"
Unfortunately and ironically, the table input syntax is the only syntax in the documentation that does not have an example :D
I'd be happy to look into this further if you attach a mat file containing the inputs to trainNetwork.
save('trainNetworkInputs.mat','xx','layers','options')
net = trainNetwork(xx,layers,options);
Walter Roberson
Walter Roberson il 12 Gen 2020
For a table, the first variable must consist either of 3D numeric arrays (which would require cell array to store in tables), or else of path names to image files, or else of path names to .mat file. Instead your first column is numeric (scalar for each row).
Chandini Govind
Chandini Govind il 13 Gen 2020
" I'd be happy to look into this further if you attach a mat file containing the inputs to trainNetwork."
Tnk u.i have attached what u requested.
The reason for your error is clearly described in the documentation. It just requires a little digging to understand the problem. I'll point you in the right direction so you can become more familiar with the documentation.
For table inputs there are actually two syntaxes. In my answer I only provided the first one below but that link would have shown you the second one, too.
In both syntaxes, it is expected that the predictor variables are in the first column of the table (see Walter's comment above). The second syntax specifies responses as the second input. If the first syntax is used instead, responses are expected to be in the second column of the table. This is all explained in this description of the table input (the link is to a different section of the same page as the previous links).
The syntax you're using fits neither description. Here are the first few rows of your table.
head(xx)
8×30 table
x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30
______ ______ ______ ______ _____ ______ _____ _____ ______ ______ _____ ______ _____ ______ ______ ______ ______ ______ ______ ______ ______ ______ ___ ______ ______ ______ ______ _____ ______ ______
138.47 51.655 97.827 27.98 0.91 124.71 2.666 3.064 41.928 197.76 1.582 1.396 0.2 32.638 1.017 0.381 51.626 2.273 -2.414 16.824 -0.277 258.73 2 67.435 2.15 0.444 46.062 1.24 -2.475 113.5
160.94 68.768 103.23 48.146 -999 -999 -999 3.473 2.078 125.16 0.879 1.414 -999 42.014 2.039 -3.011 36.918 0.501 0.103 44.704 -1.916 164.55 1 46.226 0.725 1.158 -999 -999 -999 46.226
-999 162.17 125.95 35.635 -999 -999 -999 3.148 9.336 197.81 3.776 1.414 -999 32.154 -0.705 -2.093 121.41 -0.953 1.052 54.283 -2.186 260.41 1 44.251 2.053 -2.028 -999 -999 -999 44.251
143.91 81.417 80.943 0.414 -999 -999 -999 3.31 0.414 75.968 2.354 -1.285 -999 22.647 -1.655 0.01 53.321 -0.522 -3.1 31.082 0.06 86.062 0 -999 -999 -999 -999 -999 -999 0
175.86 16.915 134.81 16.405 -999 -999 -999 3.891 16.405 57.983 1.056 -1.385 -999 28.209 -2.197 -2.231 29.774 0.798 1.569 2.723 -0.871 53.131 0 -999 -999 -999 -999 -999 -999 0
89.744 13.55 59.149 116.34 2.636 284.58 -0.54 1.362 61.619 278.88 0.588 0.479 0.975 53.651 0.371 1.329 31.565 -0.884 1.857 40.735 2.237 282.85 3 90.547 -2.412 -0.653 56.165 0.224 3.106 193.66
148.75 28.862 107.78 106.13 0.733 158.36 0.113 2.941 2.545 305.97 3.371 1.393 0.791 28.85 1.113 2.409 97.24 0.675 -0.966 38.421 -1.443 294.07 2 123.01 0.864 1.45 56.867 0.131 -2.767 179.88
154.92 10.418 94.714 29.169 -999 -999 -999 2.897 1.526 138.18 0.365 -1.305 -999 78.8 0.654 1.547 28.74 0.506 -1.347 22.275 -1.761 187.3 1 30.638 -0.715 -1.724 -999 -999 -999 30.638
Chandini Govind
Chandini Govind il 13 Gen 2020
Modificato: Chandini Govind il 13 Gen 2020
" it is expected that the predictor variables are in the first column of the table ."
does this means for 30 features i have to extract them and train along with reponse?.doesn't it look tedious?
well after converting to cell array,i done this
for i=1:30
xx=table(ft(:,i),yy);
net = trainNetwork(xx,layers,options);
end
i get this error
Error using trainNetwork (line 150)
Invalid training data. For table input, sequences must be in the first column as file paths.
Error in study8 (line 38)
net = trainNetwork(xx,layers,options);
Adam Danz
Adam Danz il 13 Gen 2020
Since you're having trouble with the table input syntax and since there are no examples for that syntax, why don't you try using the numeric array input, if possible?
because i'm getting the following error and couldn't resolve it.
Error using trainNetwork (line 150)
Invalid training data. Predictors must be a N-by-1 cell array of sequences, where N is the number of sequences. All
sequences must have the same feature dimension and at least one time step.
Error in study8 (line 37)
net = trainNetwork(ft,yy,layers,options);
Kenan
Kenan il 17 Giu 2022
Modificato: Kenan il 17 Giu 2022
For information there is an example for this method :

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Deep Learning Toolbox in Centro assistenza e File Exchange

Prodotti

Release

R2018b

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by