[68] | 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 |
|
---|
| 10 | load('birds20130709.mat');
|
---|
| 11 |
|
---|
[72] | 12 | %ixtrain = find(J == 0);
|
---|
| 13 | %ixtest = find(J == 1);
|
---|
| 14 | %z=a(ixtest,:);
|
---|
[68] | 15 |
|
---|
[72] | 16 |
|
---|
[68] | 17 | [bags, labs, bagid] = getbags(z);
|
---|
| 18 |
|
---|
| 19 |
|
---|
| 20 |
|
---|
| 21 | C = 19;
|
---|
| 22 | predictions = nan(length(bagid), 19);
|
---|
| 23 |
|
---|
| 24 |
|
---|
[72] | 25 | predictions2 = nan(length(bagid), 19);
|
---|
[68] | 26 |
|
---|
[72] | 27 | %u = simple_mil*classc;
|
---|
| 28 |
|
---|
| 29 | u = milvector([],'m')*scalem([],'variance')*libsvc*classc;
|
---|
| 30 |
|
---|
| 31 |
|
---|
[68] | 32 | %For each class, train a classifier
|
---|
| 33 | for i=1:C
|
---|
[72] | 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);
|
---|
[68] | 38 |
|
---|
[72] | 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,:);
|
---|
[68] | 47 |
|
---|
[72] | 48 | w = xtr*u;
|
---|
| 49 | out = xte*w;
|
---|
| 50 |
|
---|
| 51 |
|
---|
| 52 | predictions(:,i) = out(:,2); %Positive class is column 2
|
---|
[68] | 53 | end
|
---|
| 54 |
|
---|
| 55 |
|
---|
| 56 |
|
---|
| 57 |
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | %Write everything to a CSV file
|
---|
| 61 |
|
---|
| 62 |
|
---|
| 63 | fid = fopen('pred20130709.csv', 'w');
|
---|
[72] | 64 | fprintf(fid, '%s,%s\r\n', 'Id', 'probability');
|
---|
[68] | 65 |
|
---|
| 66 | for i=1:length(bagid)
|
---|
| 67 |
|
---|
| 68 | for j=1:C
|
---|
| 69 | if (i==length(bagid) && j==C)
|
---|
[72] | 70 | fprintf(fid, '%d,%f', bagid(i)*100+(j-1), predictions(i,j));
|
---|
[68] | 71 | else
|
---|
[72] | 72 | fprintf(fid, '%d,%f\r\n', bagid(i)*100+(j-1), predictions(i,j));
|
---|
[68] | 73 | end
|
---|
| 74 | end
|
---|
| 75 | end
|
---|
| 76 | fclose(fid);
|
---|