Switch to unified view

a b/classification/RUSboost/runRUSBoosting.m
1
function [allModels, allTraining, allTesting] = runRUSBoosting(X,Y)
2
%RUNRUSBOOSTING runs RUSBoost on a given LIDC dataset broken into two
3
%parameters, X and Y.
4
%   param X
5
%      This is the data that is input matrix that contains image features
6
%      calculated from nodules in the LIDC.
7
%   param Y
8
%      This is a cell matrix that contains semantic ratings from the LIDC.
9
%   return allModels
10
%      a cell array containing a model for each semantic characteristic.
11
%   return allTraining
12
%      a cell matrix indicating which values are testing for each semantic 
13
%      characteristic.
14
%   return allTesting
15
%      a cell matrix indicating which values are training for each 
16
%      semantic characteristic.
17
                 
18
19
20
%% Setup the data and the labels
21
    %number of semantic classes in the array 'Y'
22
    n = size(Y,2);
23
    
24
    %Semantic labels
25
    labels = {'Subtlety', 'Sphericity', 'Margin', 'Lobulation',... 
26
              'Spiculation', 'Texture', 'Malignancy'};
27
  
28
    %create a cell array containing the models
29
    allModels = cell(1,1);
30
    allTraining = cell(1,1);
31
    allTesting = cell(1,1);
32
33
    %Show distribution for each semantic label
34
    for i = 1:n
35
        fprintf('%s%s\n','Tabulation for: ', labels{i});
36
        tabulate(Y(:,i));
37
    end
38
      
39
    %create weak learner template for RUSBoosting to build an ensemble on
40
    % TODO: CHANGE THESE PARAMS TO SOMETHING ELSE
41
    t = ClassificationTree.template('MinParent',60,'minleaf',30);
42
    
43
%% Build testing and training sets
44
    
45
    %build training and testing sets
46
    for i=1:n
47
        part = cvpartition(Y(:,i),'holdout',0.25);
48
        allTraining{i} = training(part);
49
        allTesting{i} = test(part);
50
    end  
51
    
52
%% Run RUSBoosting
53
54
    %iterate through each semantic class label and run boosting
55
    for i=1:n
56
        fprintf('Growing ensemble for: %s\n',labels{i});
57
        tic
58
        tempY = Y(:,i);
59
        tempY = tempY(allTraining{i});
60
        tempX = X(allTraining{i},:);
61
        %run the RUSboost on a semantic label
62
        allModels{i} = fitensemble(tempX,tempY,'RUSBoost',1500,t,...
63
            'LearnRate',0.1,'nprint',100);
64
        toc
65
        
66
    end
67