How to apply voting for classifiers and obtain the accuracy of classification?

4 visualizaciones (últimos 30 días)
I want to combine the results of five classifiers (SVM, random forest, naive Bayes, decision tree, KNN) by majority voting. I collected the outputs of these classifiers in tt array (class labels are binary 1 or 2) then I used mode function for obtaining most frequent values in array and compared the output with ytest (test labels) to obtain tp, tn, fp, fn and compute the Rand Index accuracy of ensemble learning. But the accuracy of the classification ensemble is always obtaining 1 that It’s not right.
clear
close all
clc
load datas17.mat;
data=datas17;
[n,m]=size(data);
rows=(1:n);
test_count=floor((1/6)*n);
sum_ens=0;sum_result=0;
test_rows=randsample(rows,test_count);
train_rows=setdiff(rows,test_rows);
test=data(test_rows,:);
train=data(train_rows,:);
xtest=test(:,1:m-1);
ytest=test(:,m);
xtrain=train(:,1:m-1);
ytrain=train(:,m);
%-----------svm------------------
svm=svm1(xtest,xtrain,ytrain);
%-------------random forest---------------
rforest=randomforest(xtest,xtrain,ytrain);
%-------------decision tree---------------
DT=DTree(xtest,xtrain,ytrain);
%---------------bayesian---------------------
NBModel = NaiveBayes.fit(xtrain,ytrain, 'Distribution', 'kernel');
Pred = NBModel.predict(xtest);
dt=Pred;
%--------------KNN----------------
knnModel=fitcknn(xtrain,ytrain,'NumNeighbors',4);
pred=knnModel.predict(xtest);
sk=pred;
tt=[svm rforest DT dt sk];
output=zeros(test_count,1);
for i=1:test_count
output(i,1)=mode(tt(i,:));
end
tp_ens=0;tn_ens=0;fp_ens=0;fn_ens=0;
for i=1:test_count
if(output(i)==1 && ytest(i)==1)
tp_ens=tp_ens+1;
end
if(output(i)==2 && ytest(i)==2)
tn_ens=tn_ens+1;
end
if(output(i)==2 && ytest(i)==1)
fp_ens=fp_ens+1;
end
if(output(i)==1 && ytest(i)==2)
fn_ens=fn_ens+1;
end
end
acc_ens=(tp_ens+tn_ens)/(tp_ens+tn_ens+fp_ens+fn_ens);
disp('accuracy of classification ensemble:');
disp(acc_ens);
I'll be grateful to have your opinions about voting for these classifiers and obtaining the accuracy of classification.

Respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by