source: birds/doprediction.m @ 146

Last change on this file since 146 was 72, checked in by vcheplygina, 11 years ago
File size: 1.7 KB
Line 
1%i,j,p
2%i
3%The rec_id of a recording in the test set. Only include predictions for recordings in the test set.
4%j
5%The species/class #. For each rec_id, there should be 19 lines for species 0 through 18.
6%p
7%Your classifier's prediction about the probability that species j is present in rec_id i. This must be in the range [0,1].
8
9
10load('birds20130709.mat');
11
12%ixtrain = find(J == 0);
13%ixtest = find(J == 1);
14%z=a(ixtest,:);
15
16
17[bags, labs, bagid] = getbags(z);
18
19
20
21C = 19;
22predictions = nan(length(bagid), 19);
23
24
25predictions2 = nan(length(bagid), 19);
26
27%u = simple_mil*classc;
28
29u = milvector([],'m')*scalem([],'variance')*libsvc*classc;
30
31
32%For each class, train a classifier
33for i=1:C
34    xtr = changelablist(x,i+1);  %Bird 1 is lablist 2, etc
35    thisll = getlablistnames(xtr);
36    xtr = setname(xtr,strtrim(thisll(curlablist(xtr),:)));
37    xtr=makemillabeled(xtr);
38   
39    xte = changelablist(z,i+1);  %Bird 1 is lablist 2, etc
40    thisll = getlablistnames(xte);
41    xte = setname(xte,strtrim(thisll(curlablist(xte),:)));
42    xte=makemillabeled(xte);
43
44
45    %x = a(ixtrain, :);
46    %z = a(ixtest,:);
47   
48    w = xtr*u;
49    out = xte*w;
50   
51 
52    predictions(:,i) = out(:,2);  %Positive class is column 2
53end
54
55
56
57
58
59
60%Write everything to a CSV file
61
62
63fid = fopen('pred20130709.csv', 'w');
64fprintf(fid, '%s,%s\r\n', 'Id', 'probability');
65
66for i=1:length(bagid)
67       
68    for j=1:C
69        if (i==length(bagid) && j==C)
70            fprintf(fid, '%d,%f', bagid(i)*100+(j-1), predictions(i,j));
71        else
72            fprintf(fid, '%d,%f\r\n', bagid(i)*100+(j-1), predictions(i,j));
73        end
74    end
75end
76fclose(fid);
Note: See TracBrowser for help on using the repository browser.