Matlab SVM example -
i trying implement svm classification. goal output correct grid of origin of power signal (.wav file). grids titled a-i , there 93 total signals training set , 49 practice signals. have 93x10x36 matrix of feature vectors. know why errors shown? traincorrectgrid , training_cepstrum1 both have 93 rows don't understand problem is. appreciated.
my code shown here:
clc; clear; close all; load('avg_fft_feature (4).mat'); %training feature vectors load('practice_fft_mag_all (2).mat'); %practice feauture vectors load('practice_gridorigin.mat'); %correct grids of origin practice data load practicecorrectgrid.mat; load training_cepstrum1; load practice_cepstrum1a; load fset1.mat %load in correct practice grids traincorrectgrid=['a';'a';'a';'a';'a';'a';'a';'a';'a';'b';'b';'b';'b';'b';'b';'b';'b';'b';'b';'c';'c';'c';'c';'c';'c';'c';'c';'c';'c';'c';'d';'d';'d';'d';'d';'d';'d';'d';'d';'d';'d';'e';'e';'e';'e';'e';'e';'e';'e';'e';'e';'e';'f';'f';'f';'f';'f';'f';'f';'f';'g';'g';'g';'g';'g';'g';'g';'g';'g';'g';'g';'h';'h';'h';'h';'h';'h';'h';'h';'h';'h';'h';'i';'i';'i';'i';'i';'i';'i';'i';'i';'i';'i']; %[results,u] = multisvm(avg_fft_feature, traincorrectgrid, avg_fft_feature_practice);%avg_fft_feature); [results,u] = multisvm(training_cepstrum1(93,:,1), traincorrectgrid, practice_cepstrum1a(49,:,1)); disp('grids of origin (svm)'); %display svm results = 1:numel(u) str = sprintf('%d: %s', i, u(i)); disp(str); end %display percent correct numcorrect = 0; = 1:numel(u) %if (strcmp(traincorrectgrid(i,1), u(i))==1); %compare training %training if (strcmp(practicecorrectgrid(i,1), u(i))==1); %compare practice data training numcorrect = numcorrect + 1; end end numberofelements = numel(u); percentcorrect = numcorrect / numberofelements * 100; % percentcorrect = round(percentcorrect, 2); disppercent = sprintf('percent correct = %0.3f%%', percentcorrect); disp(disppercent);
the multisvm function shown here:
function [result, u] = multisvm(trainingset,grouptrain,testset) %models given training set corresponding group vector , %classifies given test set using svm classifier according %one vs. relation. % %this code written cody neuburger cneuburg@fau.edu %florida atlantic university, florida usa , modified renny varghese %this code adapted , cleaned anand mishra's multisvm function %found @ http://www.mathworks.com/matlabcentral/fileexchange/33170-multi-class-support-vector-machine/ u=unique(grouptrain); numclasses=length(u); result = zeros(length(testset(:,1)),1); %build models k=1:numclasses %vectorized statement binarizes group %where 1 current class , 0 other classes g1vall=(grouptrain==u(k)); models(k) = svmtrain(trainingset,g1vall); end %classify test cases j=1:size(testset,1) k=1:numclasses if(svmclassify(models(k),testset(j,:))) break; end end result(j) = k; end mapvalues = 'abcdefghi'; u = mapvalues(result);
you state training_cepstrum1
has size [93,10,36]. when call multisvm
, passing in training_cepstrum1(93,:,1)
has size [1,10]. since traincorrectgrid
has size [93,1], there mismatch in number of rows.
it looks make same error when passing in practice_cepstrum1a
.
try replacing call multisvm
with
[results,u] = multisvm(training_cepstrum1(:,:,1), traincorrectgrid, practice_cepstrum1a(:,:,1));
this way training_cepstrum1(:,:,1)
has size [93,10], same number of rows traincorrectgrid
.
Comments
Post a Comment