How to plot ROC curve?

1 回表示 (過去 30 日間)
Karolina
Karolina 2015 年 11 月 25 日
編集済み: Natsu dragon 2018 年 2 月 3 日
I have dataset which I classified using 10 different thresholds. Then I evaluated true and false positive rate (TPR, FPR) to generate ROC curve. However, the curve looks strange. Did I evaluated the curve correctly? Below is the code which I used to generate ROC curve.
TPR=[0.214091009346534 0.231387608987612 0.265932891531049 ...
0.324782536928746 0.407704239947213 0.497932979272465 ...
0.566189022386499 0.587833185570207 0.546182718263242 ...
0.434923996561788];
FPR=[0.006017495627892 0.008669605012233 0.013377312018797 ...
0.022621821298088 0.039994426565193 0.069264094928662 ...
0.108694153334795 0.148784394110204 0.178634096117665 ...
0.194756822274831];
plot(FPR,TPR);
  2 件のコメント
Cretu Calin
Cretu Calin 2017 年 4 月 7 日
I think that the last two values are wrong. You cannot have any point in the right side of the diagonal [(0,0),(1,1)].
Image Analyst
Image Analyst 2017 年 4 月 7 日
Cretu, please explain why believe the last two points are to the right of the 0-to-1 diagonal:

サインインしてコメントする。

採用された回答

Thorsten
Thorsten 2015 年 11 月 25 日
I agree that the curves look strange. If you decrease the threshold, you cannot get a smaller true positive rate. The rate can only stay the same or increase. So your two points at the end of the curve are wrong. Also, you should vary your threshold through the full range, from max to 0, such that your curve starts from (0,0) and ends at (1,1).
  9 件のコメント
Thorsten
Thorsten 2015 年 11 月 25 日
編集済み: Thorsten 2015 年 11 月 25 日
You have to restrict all computations to the valid indices:
valid_ind = R > -3.40e+38;
P = nnz(GT(valid_ind)); % number of positive responses in ground truth
N = nnz(1-GT(valid_ind));
and in the loop
tp(i) = nnz(Rt(valid_ind) & GT(valid_ind));
fp(i) = nnz(Rt(valid_ind) & ~GT(valid_ind));
The best way to do it is to write a function
function [TPR, FPR] = roc(GT, R, thresholds)
and call this function with
GT(valid_ind), R(valid_ind)
in case you have to exclude some pixels from the analysis.
Natsu dragon
Natsu dragon 2018 年 2 月 3 日
編集済み: Natsu dragon 2018 年 2 月 3 日
hello, i have used the same code with your attached data and i got results, but when i used it with my own results i got nothing, it didn't plots. can you help me to understand why?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDetection についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by