-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecBoot.m
More file actions
59 lines (48 loc) · 1.51 KB
/
Copy pathDecBoot.m
File metadata and controls
59 lines (48 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
%# load data
[ ServiceName, Region, Availability, Outages, DownTime ] = ReadCloudDataSet();
SLAavailability(:,:)=100;
for i=1:length(Availability)
if(100-Availability(i)<0.2753)
InitialTrust(i) = 1;
else
InitialTrust(i) = 0;
end
end
M=zeros(size(Availability,1),6);
for db=1:size(M,1)
%M(db,1)=ServiceName(db);
%M(db,2)= Region(db);
M(db,3)= Availability(db);
M(db,4)= Outages(db);
%M(db,5)= DownTime(db);
M(db,6)= InitialTrust(db);
end
%# construct predicting attributes and target class
vars = {'Availability' 'Outages'};
x = [Availability Outages]; %# mixed continous/discrete data
y = InitialTrust; %# class labels
disp('data');
disp(y);
%# train classification decision tree
t = classregtree(x, y, 'method','classification', 'names',vars, ...
'categorical',[6], 'prune','off');
view(t)
%# test
yPredicted = str2num( cell2mat( eval(t, x)));
cm = confusionmat(y,yPredicted); %# confusion matrix
N = sum(cm(:));
err = ( N-sum(diag(cm)) ) / N; %# testing error
disp('test error');
disp(err);
%# prune tree to avoid overfitting
tt = prune(t, 'level',3);
view(tt)
%# predict a new unseen instance
t = fitctree(x, y, 'PredictorNames',vars, ...
'CategoricalPredictors',{'Cylinders', 'Model_Year'}, 'Prune','off');
view(t, 'mode','graph')
y_hat = predict(t, x);
cm = confusionmat(y,y_hat);
tt = prune(t, 'Level',3);
view(tt)
predict(tt, [33 4 78 NaN])