Error using gather when using predict (from ClassificationKNN)

조회 수: 9 (최근 30일)
Camilo
Camilo 2023년 7월 13일
답변: chadows 2024년 6월 20일
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
Ayush Aniket
Ayush Aniket 2023년 8월 22일
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 2023년 8월 22일
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

댓글을 달려면 로그인하십시오.

채택된 답변

Milan Bansal
Milan Bansal 2023년 8월 31일
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
Camilo
Camilo 2023년 9월 2일
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 2024년 3월 20일
Thank you very much, your tips are very good, and also solve the RF problem

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

chadows
chadows 2024년 6월 20일
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.
:)

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by