how to compare a vector with a column of a matrix?

조회 수: 2 (최근 30일)
Apurva Jariwala
Apurva Jariwala 2019년 3월 20일
답변: Apurva Jariwala 2019년 3월 20일
I designed a simple decision tree to work on the Iris data set, with two values for input: petal width and petal length, and one output: versicolor or virginica (only these samples were taken) I want to measure the accuracy of each class and for that I am trying to compare the output of my tree to the species column of the iris dataset. Please let me know what changes can I do to the code:
Totalsamples = size(Petal_length,1);
predictedclass=[];
for i=51:Totalsamples
if Petal_length(i) < 4.8 && Petal_width(i) < 1.7
clspred = 2;
else
clspred = 3;
end
predictedclass = [predictedclass; clspred];
end
truepred2 = [];
for j = 1:50
if predictedclass(j) == 2
tpred = 2;
end
truepred2 = [truepred2; tpred];
end
truepred3 = [];
for l = 51:100
if predictedclass(l) == 3
tpred3 = 3;
end
truepred3 = [truepred3; tpred3];
end
Reqdsamples = [versicolor; virginica];
truelabel = Reqdsamples(:,5);
cpt = classperf(truelabel,predictedclass);
accuracy_for_versicolor = size(truepred2,1)/size(versicolor,5);
accuracy_for_virginica = size(truepred3,1)/size(virginica,5);
disp(cpt.correctrate)
  댓글 수: 2
Kevin Phung
Kevin Phung 2019년 3월 20일
편집: Kevin Phung 2019년 3월 20일
any chance you can provide numerical examples to help convey your question?
'Please let me know what changes can I do to the code:'
are you asking if your code can be improved, or are you trying to do something that you do not know how to do? or both?
Apurva Jariwala
Apurva Jariwala 2019년 3월 20일
I am trying to find the accuracy of the classification for versicolor and virginica classes individually. The code that I used is not able to do so. I tried using a for loop but it was still not working.
I just need to find the accuracy individually for each class. I need some help doing that

댓글을 달려면 로그인하십시오.

채택된 답변

Apurva Jariwala
Apurva Jariwala 2019년 3월 20일
Totalsamples = size(Petal_length,1);
predictedclass=[];
for i=51:Totalsamples
if Petal_length(i) < 4.8 && Petal_width(i) < 1.7
clspred = 2;
else
clspred = 3;
end
predictedclass = [predictedclass; clspred];
end
Reqdsamples = [versicolor; virginica];
truelabel = Reqdsamples(:,5);
cpt = classperf(truelabel,predictedclass);
cmat = confusionmat(truelabel,predictedclass);
trueclas=[];
trueclas = diag(cmat);
Nos = size(truelabel, 1)/2;
accuracy_for_versicolor = trueclas(1)/Nos;
accuracy_for_virginica = trueclas(2)/Nos;
disp(cpt.correctrate)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by