fitcknn using Mel-frequency cepstral coefficients (MFCCs)

1 次查看(过去 30 天)
Hello everyone,
I'm using a function provided by my professor to use kNN algorith for classification for getting the highest rate recognition with different neighbors, but I'm getting the following errors
Error using classreg.learning.FullClassificationRegressionModel.prepareDataCR (line 234)
X and Y do not have the same number of observations.
Error in classreg.learning.classif.FullClassificationModel.prepareData (line 821)
classreg.learning.FullClassificationRegressionModel.prepareDataCR(...
Error in ClassificationKNN.prepareData (line 926)
prepareData@classreg.learning.classif.FullClassificationModel(X,Y,varargin{:},'OrdinalIsCategorical',true);
Error in classreg.learning.FitTemplate/fit (line 233)
this.PrepareData(X,Y,this.BaseFitObjectArgs{:});
Error in ClassificationKNN.fit (line 911)
this = fit(temp,X,Y);
Error in fitcknn (line 264)
this = ClassificationKNN.fit(X,Y,RemainingArgs{:});
Error in kNN_algorithm_features (line 13)
Mdl = fitcknn(trainSet',trainLabel','NumNeighbors',k(kk));
Using audio data provided from him, i'm able to use it, but when i try to use my own audio, it gives me that error.
We did that for every time features of audio (Spectral Centroid, Spread, Rolloff and MFCCs) but this error appears only with MFCC.
% function [a,b]=kNN_algorithm_features(trainSet, testSet, trainLabel, testLabel)
load('matlab.mat');
trainSet = MFCC_trainSet;
testSet = MFCC_testSet;
trainLabel = MFCC_trainSet_label;
testLabel = MFCC_testSet_label;
rate=[];
k=[1 5 10 15 20];
for kk=1:length(k)
disp(['set-up the kNN... number of neighbors: ',mat2str(k(kk))])
Mdl = fitcknn(trainSet',trainLabel','NumNeighbors',k(kk));
% test the kNN
predicted_label = predict(Mdl, testSet');
% measure the performance
correct = 0;
flag = zeros(1,length(predicted_label));
for i=1:length(predicted_label)
if length(testLabel) >= i
if predicted_label(i)==testLabel(i)
correct=correct+1;
flag(i) = 1;
end
end
end
disp('recognition rate:')
rate(kk) = (correct/length(predicted_label))*100
end
[a,b]=max(rate);
For the .mat file, I cannot attach it but I'm gonna paste here how it looks like
MFCC_testSet 13x216712 double
MFCC_testSet_label 1x216712 double
MFCC_trainSet 13x219236 double
MFCC_trainSet_label 1x216972 double
  • MFCC_trainSet_label and MFCC_testSet_label are just series of 1, for comparing them
  • MFCC_trainSet contains the MFCC values of all songs
  • MFCC_testSet contains the MFCC values of the test songs
What am I doing wrong?

采纳的回答

Shiva Kalyan Diwakaruni
Hi,
The error "X and Y do not have the same number of observations." is occurring because In this case X which is trainSet' is 219236x13 double has 219236 observations where as Y which is trainLabel' which is of size 216972x1 double has 216972 observations hence as number of training observations is not same as number of training Labels Your code is not being executed .Hence make sure both trainSet and trainLabel has same number of rows.
Hope it helps.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by