Error using gather when using predict (from ClassificationKNN)

6 visualizaciones (últimos 30 días)
Thanks in advance.
My code uses ClassfificationKNN to predict classes for my data. The error I get is as follows:
Error using gather
Too many input arguments.
Error in ClassificationKNN/score (line 451)
[CIDX,dist,gindex,W] = gather(CIDX,dist,gindex,W);
Error in ClassificationKNN/predict (line 777)
[posteriors,gindex,CIDX] = score(this,X);
Using the debugger, line 451 raises the issue when trying to Transfer distributed array.
Part of the code I use (portion pertaining to this question):
Note: attached is one sample of training and testing dataset since this is embededded in a for loop.
dist_measure = {'cosine'; 'correlation'; 'spearman';};
distMeas = dist_measure{2};
distWeight = 'inverse';
breakties = 'nearest';
nNeighbors1 = 1;
nNeighbors2 = 9;
training_labels1 = items(ind); %111x1 (1,2,3...28)
training_labels2 = category(ind); %111x1 (1,1,1...2,2,2)
true_label1 = items(indtest); %exemplar (e.g., 1)
true_label2 = category(indtest); %category (e.g., 1)
%from https://lvdmaaten.github.io/drtoolbox/
if DRflag
%% Performs out-of-sample extension of the new datapoints in points.
training_data = out_of_sample(training_data,mapping0); %111x11 (convert 11 objects into 11 feature vectors)
predicted_data = out_of_sample(predicted_data,mapping0); %1 x 11
end
mdl1 = fitcknn(training_data,training_labels1,'distance',distMeas,'DistanceWeight',distWeight,...
'NumNeighbors',nNeighbors1,'BreakTies',breakties); %item decoding
mdl2 = fitcknn(training_data,training_labels2,'distance',distMeas,'DistanceWeight',distWeight,...
'NumNeighbors',nNeighbors2,'BreakTies',breakties); %category decoding
predicted_label1 = predict(mdl1,predicted_data);
predicted_label2 = predict(mdl2,predicted_data);
  2 comentarios
Ayush Aniket
Ayush Aniket el 22 de Ag. de 2023
Hi Camilo,
I implemented the code you shared with the data provided as shown below:
dist_measure = {'cosine'; 'correlation'; 'spearman';};
distMeas = dist_measure{2};
distWeight = 'inverse';
breakties = 'nearest';
nNeighbors1 = 1;
nNeighbors2 = 9;
training_labels1 = load('training_labels1.txt');
training_labels2 = load('training_labels2.txt');
training_data = load('training_data.txt');
predicted_data = load('predicted_data.txt');
mdl1 = fitcknn(training_data,training_labels1,'distance',distMeas,'DistanceWeight',distWeight,...
'NumNeighbors',nNeighbors1,'BreakTies',breakties); %item decoding
mdl2 = fitcknn(training_data,training_labels2,'distance',distMeas,'DistanceWeight',distWeight,...
'NumNeighbors',nNeighbors2,'BreakTies',breakties); %category decoding
predicted_label1 = predict(mdl1,predicted_data);
predicted_label2 = predict(mdl2,predicted_data);
I am not getting any error. I got the following values as answer.
predicted_label1 = 12
predicted_label2 = 1
Let me know in case of any discrepancies.
Camilo
Camilo el 22 de Ag. de 2023
Thank you for your reply @Ayush Aniket!
The issue has been with my Matlab with the
Error using gather
I am still unsure of why that error shows in my machine but not in others. Regardless, I appreciate you trying.
With gratitude,
Camilo

Iniciar sesión para comentar.

Respuesta aceptada

Milan Bansal
Milan Bansal el 31 de Ag. de 2023
Hi,
I understand that you are getting an error: "Too many input arguments" while using MATLAB's gather function.
It looks like the MATLAB's gather function that you are using is being shadowed by some other function or script with the same name. You can check the list of all functions or files with the name gather in the MATLAB path by the running the command as shown below.
which gather -all
Rename the shadowed file or remove it from the MATLAB path to resolve the issue.
Refer to the documentation link below to know about MATLAB's “gather” function in different toolboxes.
  3 comentarios
Camilo
Camilo el 2 de Sept. de 2023
Thank you this was helpful. It seemed like one of my toolboxes (eeglab) also had a 'gather' function for parallel computing that was interfering with the Matlab process.
Thank you both!
tiecheng
tiecheng el 20 de Mzo. de 2024
Thank you very much, your tips are very good, and also solve the RF problem

Iniciar sesión para comentar.

Más respuestas (1)

chadows
chadows el 20 de Jun. de 2024
I have tried to delete those files under this path:
D:\MATLAB\toolbox\eeglab\plugins\ICLabel\matconvnet\matlab\compatibility\parallel\
but when I add
g = which('gather');
disp(g);
code in D:\MATLAB\toolbox\stats\classreg\ClassificationKNN.m line 452, I found "g" is still "D:\MATLAB\toolbox\eeglab\plugins\ICLabel\matconvnet\matlab\compatibility\parallel\gather.m".
Finally, I delete the path: D:\MATLAB\toolbox\eeglab\plugins\ICLabel\matconvnet\matlab\compatibility\parallel\.
Then I succeeded.
>> which('gather')
D:\MATLAB\toolbox\matlab\bigdata\gather.m
I wonder if there is any other better ways.
:)

Categorías

Más información sobre Statistics and Machine Learning Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by