How do I use fscmrmr with the outputs from the MATLAB example titled "Classify Sound Using Deep Learning"?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Nicholas Pulsone
il 17 Gen 2024
Commentato: Nicholas Pulsone
il 22 Gen 2024
I want to assess the importance of the featuers used in the MATLB example "Classify Soound Using Deep Learning". I am new to AI/ML and learned about the function fscmrmr. How do I use this function with the variables contained the in the MATLAB code below?
I tried entering [idx,scores] = fscmrmr(featuresTrain,labelsTrain); and received the following error...
Error using classreg.learning.classif.FullClassificationModel.prepareData
X must be a numeric matrix.
Error in fscmrmr (line 119)
classreg.learning.classif.FullClassificationModel.prepareData(...
Please note, the code below was copied directly from the online MATLAB example that shows how to classify a sound by using deep learning processes.
fs = 44.1e3;
duration = 0.5;
N = duration*fs;
wNoise = 2*rand([N,1000]) - 1;
wLabels = repelem(categorical("white"),1000,1);
bNoise = filter(1,[1,-0.999],wNoise);
bNoise = bNoise./max(abs(bNoise),[],'all');
bLabels = repelem(categorical("brown"),1000,1);
pNoise = pinknoise([N,1000]);
pLabels = repelem(categorical("pink"),1000,1);
sound(wNoise(:,1),fs)
melSpectrogram(wNoise(:,1),fs)
title('White Noise')
sound(bNoise(:,1),fs)
melSpectrogram(bNoise(:,1),fs)
title('Brown Noise')
sound(pNoise(:,1),fs)
melSpectrogram(pNoise(:,1),fs)
title('Pink Noise')
audioTrain = [wNoise(:,1:800),bNoise(:,1:800),pNoise(:,1:800)];
labelsTrain = [wLabels(1:800);bLabels(1:800);pLabels(1:800)];
audioValidation = [wNoise(:,801:end),bNoise(:,801:end),pNoise(:,801:end)];
labelsValidation = [wLabels(801:end);bLabels(801:end);pLabels(801:end)];
aFE = audioFeatureExtractor("SampleRate",fs, ...
"SpectralDescriptorInput","melSpectrum", ...
"spectralCentroid",true, ...
"spectralSlope",true);
featuresTrain = extract(aFE,audioTrain);
[numHopsPerSequence,numFeatures,numSignals] = size(featuresTrain)
featuresTrain = permute(featuresTrain,[2,1,3]);
featuresTrain = squeeze(num2cell(featuresTrain,[1,2]));
numSignals = numel(featuresTrain)
[numFeatures,numHopsPerSequence] = size(featuresTrain{1})
featuresValidation = extract(aFE,audioValidation);
featuresValidation = permute(featuresValidation,[2,1,3]);
featuresValidation = squeeze(num2cell(featuresValidation,[1,2]));
layers = [ ...
sequenceInputLayer(numFeatures)
lstmLayer(50,"OutputMode","last")
fullyConnectedLayer(numel(unique(labelsTrain)))
softmaxLayer
classificationLayer];
options = trainingOptions("adam", ...
"Shuffle","every-epoch", ...
"ValidationData",{featuresValidation,labelsValidation}, ...
"Plots","training-progress", ...
"Verbose",false);
net = trainNetwork(featuresTrain,labelsTrain,layers,options);
wNoiseTest = 2*rand([N,1]) - 1;
classify(net,extract(aFE,wNoiseTest)')
bNoiseTest = filter(1,[1,-0.999],wNoiseTest);
bNoiseTest= bNoiseTest./max(abs(bNoiseTest),[],'all');
classify(net,extract(aFE,bNoiseTest)')
pNoiseTest = pinknoise(N);
classify(net,extract(aFE,pNoiseTest)')
0 Commenti
Risposta accettata
Brian Hemmat
il 19 Gen 2024
Modificato: Brian Hemmat
il 19 Gen 2024
fscmrmr doesn't have any concept of time/continuity over time. To use it, consider each time step separately. For that reason, it may not be the best feature selection tool to use with an RNN network, which considers how features change over time.
However, I think this is what you want:
% Convert train features to matrix. Rows correspond to observations
X = cat(2,featuresTrain{:})';
% Replicate labels so they are in one-to-one correspondance with features.
Y = repelem(labelsTrain,size(featuresTrain{1},2),1);
[featureSelectionIdx,featureSelectionScores] = fscmrmr(X,Y);
figure
bar(featureSelectionScores)
ylabel("Feature Score")
xlabel("Feature Matrix Column")
% You can map the Feature Matrix Column back to the feature using info:
info(aFE)
See this example for a more robust way of doing this:
So, based on fscmrmr, it looks like the spectralSlope is actually the best of the two features. But again, this type of feature selection might not be optimal for an RNN. A more involved approach might be sequential feature selection, which is done in this example:
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Image Data Workflows in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!