Switch to unified view

a b/Semantic Features/NotUsed/dtLearning.m
1
function [ classValue, errorRate ] = dtLearning(X, Y, category)
2
%dtLearning Builds decion trees on a subset, tets on the rest and
3
%returns the perfect errror. Repeats to get a value for all samples
4
%Category Selection:
5
%1 subtlety, 2 sphericity, 3 margin, 4 lobulation, 5 spiculation, 6 texture, 7 malignancy
6
7
Y = Y(:,category);
8
9
%Perform random sampling by just jumbling up the data then slicing the new
10
%set into 4ths or nths.
11
divisions = 10;
12
numSamples = size(X,1);
13
testSize = round(numSamples/divisions);
14
15
%get a random order of our rows
16
randomRows = randsample(numSamples, numSamples);
17
18
%get vector of row order to undo the scrambling of the rows
19
for i = 1:numSamples
20
    restoreRows(i) = find(i == randomRows);
21
end
22
23
Xmixed = X(randomRows,:);
24
Ymixed = Y(randomRows,:);
25
26
%perform process repeatedly with the test set different each time untill
27
%all are covered.
28
classValue = 0;
29
testrows = cell(divisions,1);
30
for i = 1:(divisions - 1) %perform all iterations guaranteeed to have a full share
31
    %start with testing at the beginning rows, then cycle down
32
    testrows{i} = [(i-1)*testSize + 1:i*testSize];
33
    
34
    Xtest = Xmixed(testrows{i}, :);
35
    Ytest = Ymixed(testrows{i}, :);
36
    
37
    Xtrain = Xmixed;
38
    Xtrain(testrows{i},:) = [];
39
    Ytrain = Ymixed;
40
    Ytrain(testrows{i},:) = [];
41
    
42
    tree = classregtree(Xtrain, Ytrain);
43
    classValue = vertcat(classValue, eval(tree,Xtest));
44
end
45
%collect all the remaining rows. Could be undersized, but eliminates
46
%problems of some rows getting lost
47
testrows{divisions} = [(divisions-1)*testSize + 1:numSamples];
48
    
49
Xtest = Xmixed(testrows{divisions}, :);
50
Ytest = Ymixed(testrows{divisions}, :);
51
52
Xtrain = Xmixed;
53
Xtrain(testrows{divisions},:) = [];
54
Ytrain = Ymixed;
55
Ytrain(testrows{divisions},:) = [];
56
    
57
tree = classregtree(Xtrain, Ytrain);
58
classValue = vertcat(classValue(2:end,:), eval(tree,Xtest)); %Chop off the zero we put at the beginning
59
60
%Resort everything to the original order so we can compare against other
61
%algorithms
62
classValue = classValue(restoreRows,:);
63
64
%perform RMSE on allll the samples
65
errorRate = RMSE(classValue, Y); %RMSE error. Maybe better as an array so we can combine in the future
66
67
68
end
69