ROC curve with multiclass SVM
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hello All,
I am plotting the ROC curve for SVM multiclass(3 classes) task. Getting the error as "Index in position 2 exceeds array bounds (must not exceed 3)"
Error in ROC_SVM (line 70)
scores = double(score(:,final_best_SVM.ClassNames + 1))'; % Compute the posterior probabilities (scores)
My code is
%% Plotting ROC curve for SVM
[predictedLabels,score,cost] = predict(final_best_SVM, features_Testing);
scores = double(score(:,final_best_SVM.ClassNames + 1))'; % Compute the posterior probabilities (scores)
figure(2)
plotroc(dtTest_lab,scores)
title('ROC Curve for SVM')
댓글 수: 1
Gorkem Akgul
2021년 5월 14일
Could you solve the problem ?
채택된 답변
Harsha Priya Daggubati
2020년 4월 7일
Hi,
The number of columns of score matrix will be equal to your classes, in your case it is 3. Since you are using +1 in the following line, this issue pops up.
scores = double(score(:,final_best_SVM.ClassNames + 1))
댓글 수: 18
kav
2020년 4월 7일
Thank you for the answer. If i change ClassNames + 1 it to ClassNames + 0 it should work right but isn't.
What other changes should i make?
Thank you
What is the issue when changed to 0?
kav
2020년 4월 7일
it just gives one diagonal line no curves.
Harsha Priya Daggubati
2020년 4월 7일
편집: Harsha Priya Daggubati
2020년 4월 7일
Can you try using this:
[Xnb,Ynb,Tnb,AUCnb] = perfcurve(dtTest_lab,score(:,final_best_SVM.ClassNames(1)),'true');
plot(Xnb,Ynb);
Do the same for each class.
kav
2020년 4월 7일
tried the above code got error as
Error using perfcurve>preparedata (line 1270)
You must pass scores as a vector of floating-point values.
Error in perfcurve (line 393)
[scores,cls,weights,ncv] = preparedata(scores,cls,weights);
Error in ROC_SVM (line 99)
[Xnb,Ynb,Tnb,AUCnb] = perfcurve(dtTest_lab,score(:,final_best_SVM.ClassNames),'true');
I edited the recent reply. Can you try using it.
kav
2020년 4월 7일
Thank you so much for your time. But still i am getting error
Error using perfcurve>preparedata (line 1282)
The size of scores does not match the size of labels.
Error in perfcurve (line 393)
[scores,cls,weights,ncv] = preparedata(scores,cls,weights);
if i send my full code will it be easier for to solve?
Yeah that would help me better!
Harsha Priya Daggubati
2020년 4월 7일
편집: Harsha Priya Daggubati
2020년 4월 7일
Hi,
I assume the SVM trained is working fine. ROC usually plots TPR Vs FPR and is mostly used for binary classification. To extend it for multi-class classification you have to binarize the output - one ROC curve can be drawn for label.
So, I guess doing this for every class works:
[Xnb,Ynb,Tnb,AUCnb] = perfcurve(dtTest_lab(1),score(:,final_best_SVM.ClassNames(1)),'true');
kav
2020년 4월 7일
Thanks again, i edited my code. but same error
figure
[predictedLabels,score,cost] = predict(final_best_SVM, features_Testing);
[Xnb,Ynb,Tnb,AUCnb] = perfcurve(dtTest_lab(1),score(:,final_best_SVM.ClassNames(1)),'true');
plot(Xnb,Ynb);
hold on
[Xnb2,Ynb2,Tnb2,AUCnb2] = perfcurve(dtTest_lab(2),score(:,final_best_SVM.ClassNames(2)),'true');
plot(Xnb2,Ynb2);
hold on
[Xnb3,Ynb3,Tnb3,AUCnb3] = perfcurve(dtTest_lab(3),score(:,final_best_SVM.ClassNames(3)),'true');
plot(Xnb3,Ynb3);
xlabel('False positive rate')
ylabel('True Positive rate')
hold off
Harsha Priya Daggubati
2020년 4월 7일
편집: Harsha Priya Daggubati
2020년 4월 7일
What was the error? Try converting scores to double as you did previously
kav
2020년 4월 7일
edited the code, and got the error as below
figure
[predictedLabels,score,cost] = predict(final_best_SVM, features_Testing);
score = double(score(:,final_best_SVM.ClassNames));
[Xnb,Ynb,Tnb,AUCnb] = perfcurve(dtTest_lab(1),score(:,final_best_SVM.ClassNames(1)),'true');
plot(Xnb,Ynb);
hold on
[Xnb2,Ynb2,Tnb2,AUCnb2] = perfcurve(dtTest_lab(2),score(:,final_best_SVM.ClassNames(2)),'true');
plot(Xnb2,Ynb2);
hold on
[Xnb3,Ynb3,Tnb3,AUCnb3] = perfcurve(dtTest_lab(3),score(:,final_best_SVM.ClassNames(3)),'true');
plot(Xnb3,Ynb3);
xlabel('False positive rate')
ylabel('True Positive rate')
hold off
Error using perfcurve>preparedata (line 1282)
The size of scores does not match the size of labels.
Error in perfcurve (line 393)
[scores,cls,weights,ncv] = preparedata(scores,cls,weights);
Error in ROC_SVM (line 110)
[Xnb,Ynb,Tnb,AUCnb] = perfcurve(dtTest_lab(1),score(:,final_best_SVM.ClassNames(1)),'true');
This should work fine. Can you share the csv file too. Ill look into this in much detail
kav
2020년 4월 7일
yes attached the file.
Hi, the target you are specifying must be in a binary format (0 and 1) as you are dealing with each class.
figure
[predictedLabels,score,cost] = predict(final_best_SVM, features_Testing);
score = double(score(:,final_best_SVM.ClassNames));
[Xnb,Ynb,Tnb,AUCnb] = perfcurve(classes_Testing==1,score(:,final_best_SVM.ClassNames(1)),'true');
plot(Xnb,Ynb);
hold on
[Xnb2,Ynb2,Tnb2,AUCnb2] = perfcurve(classes_Testing==2,score(:,final_best_SVM.ClassNames(2)),'true');
plot(Xnb2,Ynb2);
hold on
[Xnb3,Ynb3,Tnb3,AUCnb3] = perfcurve(classes_Testing==3,score(:,final_best_SVM.ClassNames(3)),'true');
plot(Xnb3,Ynb3);
xlabel('False positive rate')
ylabel('True Positive rate')
hold off
kav
2020년 4월 8일
Thank you so much for your time and help. It worked!
What is the issue with this case?
kav
2020년 4월 8일
I think its same as before problem.
Error using network/sim (line 270)
Input data sizes do not match net.inputs{1}.size.
Error in ROC_MLP (line 79)
simpleclusterOutputs = sim(netBest,features_Training)
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Detection에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
