matlab libsvm multiclass one against all classification -
i new classification , trying multiclass classification using libsvm. have song features , want classify in 3 classes. code works output (pred) give 1 label test data. example pred = [2;2;2;2]; change has not effect on output. not getting going wrong. can me out pls. below code
load 113gender s=cellstr(types); [~,~,labels] = unique(s); data = allfeature; numinst = size(data,1); numlabels = max(labels); numtest = size(alltest,1); traindata = data; trainlabel = labels; testdata = alltest; %testlabel = ones(22,1); %testlabel = [1;1;1;1;1;1;2;2;2;2;2;2;2;2;3;3;3;3;3;3;3;3]; testlabel = [3;3;3;3;3;3;2;2;2;2;2;2;2;2;1;1;1;1;1;1;1;1]; %# train one-against-all models model = cell(numlabels,1); k=1:numlabels model{k} = svmtrain(double(trainlabel==k), traindata, '-c 1 -g 0.2 -b 1'); end %# probability estimates of test instances using each model prob = zeros(numtest,numlabels); k=1:numlabels [~,~,p] = svmpredict(double(testlabel==k), testdata, model{k}, '-b 1'); prob(:,k) = p(:,model{k}.label==1); %# probability of class==k end %# predict class highest probability [~,pred] = max(prob,[],2); acc = sum(pred == testlabel) ./ numel(testlabel) c = confusionmat(testlabel, pred)
Comments
Post a Comment