Attachment 'sheet12.m'
Download 1 function sheet12
2 % ROC-curves
3
4 sheet12_data % loads X, Y, Y1 and Y2
5
6 % plot the data
7 figure(1)
8 plot(X(Y == 1, 1), X(Y == 1, 2), 'r+', ...
9 X(Y == -1, 1), X(Y == -1, 2), 'bo');
10 legend('positive', 'negative');
11
12 % plot the first Ys
13 figure(2)
14 scatter(X(:, 1), X(:, 2), 20, Y1, 'filled');
15 title('predicitons 1')
16
17 figure(3)
18 scatter(X(:, 1), X(:, 2), 20, Y2, 'filled');
19 title('predicitons 2')
20
21 figure(4)
22 [FPR1, TPR1] = roc_curve(Y, Y1);
23 [FPR2, TPR2] = roc_curve(Y, Y2);
24 title('ROC')
25 plot(FPR1, TPR1, 'r-', FPR2, TPR2, 'b-')
26 legend('1', '2');
27 xlabel('false positive rate')
28 ylabel('true positive rate')
29
30 figure(5)
31 [P1, R1] = pr_curve(Y, Y1);
32 [P2, R2] = pr_curve(Y, Y2);
33 title('ROC')
34 plot(P1, R1, 'r-', P2, R2, 'b-')
35 legend('1', '2');
36 xlabel('precision');
37 ylabel('recall');
38
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 %
41 % Your solutions below
42
43 % 1a. count the number of false positives. Yt are the true labels, Yp are the
44 % predicted ones.
45 function N = fp(Yt, Yp)
46 % ...
47
48 % 1b. count the number of true positives.
49 function N = tp(Yt, Yp)
50 % ...
51
52 % 1c. count the number of false negatives.
53 function N = fn(Yt, Yp)
54 % ...
55
56 % 1d. count the number of true negatives.
57 function N = tn(Yt, Yp)
58 % ...
59
60 % 2a. compute the false positive rate between Yt and Yp, where Yt are the
61 % true labels and Yp are the predicted labels.
62 function R = fpr(Yt, Yp)
63 % ...
64
65 % 2b. compute the true positive rate
66 function R = tpr(Yt, Yp)
67 % ...
68
69 % 2c. compute the precision
70 function R = precision(Yt, Yp)
71 % ...
72
73 % 2d. compute the recall
74 function R = recall(Yt, Yp)
75 % ...
76
77 % 3a. Compute the values for the roc-curve
78 function [FPR, TPR] = roc_curve(Yt, Yp)
79 % ...
80
81 % 3b. compute the values for the precision-recall curve
82 function [P, R] = pr_curve(Yt, Yp)
83 % ...
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.