How can I get the prediction matrix to use in voting between two classifiers?

1 回表示 (過去 30 日間)
sun rise
sun rise 2022 年 4 月 28 日
function [result] = multisvm(TrainingSet,Group_Train1,TestSet,Group_Test1)
%Models a given training set with a corresponding group vector and
%classifies a given test set using an SVM classifier according to a
%one vs. all relation.
%
%This code was written by Cody Neuburger cneuburg@fau.edu
%Florida Atlantic University, Florida USA...
%This code was adapted and cleaned from Anand Mishra's multisvm function
%found at http://www.mathworks.com/matlabcentral/fileexchange/33170-multi-class-support-vector-machine/
u=unique(Group_Train1);
numClasses=length(u);
result = categorical.empty();
%build models
models = cell(numClasses,1);
for k=1:numClasses
%Vectorized statement that binarizes Group
%where 1 is the current class and 0 is all other classes
G1vAll=(Group_Train1==u(k));
models{k} = fitcsvm(TrainingSet,G1vAll,'KernelFunction','polynomial','polynomialorder',3,'Solver','ISDA','Verbose',0,'Standardize',true);
if ~models{k}.ConvergenceInfo.Converged
fprintf('Training did not converge for class "%s"\n', string(u(k)));
end
end
%classify test cases
for t=1:size(TestSet,1)
matched = false;
for k = numClasses:-1:1
% for k =1: numClasses
if(predict(models{k},TestSet(t,: )))
matched = true;
break;
end
end
if matched
result(t,1) = u(k);
%result(t) = u(k);
else
result(t,1) = 'No Match';
%--------------------------------
end
end
%Accuracy = mean(Group_Test1==result) * 100;
%fprintf('Accuracy = %.2f\n', Accuracy);
%fprintf('error rate = %.2f\n ', mean(result ~= Group_Test1 ) * 100);
end

回答 (0 件)

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by