Error using gather when using predict (from ClassificationKNN)
Afficher commentaires plus anciens
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 commentaires
Ayush Aniket
le 22 Août 2023
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
le 22 Août 2023
Réponse acceptée
Plus de réponses (1)
chadows
le 20 Juin 2024
0 votes
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.
:)
Catégories
En savoir plus sur Statistics and Machine Learning Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!