-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexampleRandomForest.m
More file actions
42 lines (33 loc) · 995 Bytes
/
exampleRandomForest.m
File metadata and controls
42 lines (33 loc) · 995 Bytes
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
clear
for i = 1
n = 1000;
v = 1000;
t = 1000;
d = 12;
k = 5;
featureType = 's';
labelSize = 1;
seed= 0;
PRNGtype = 'yasha';
[X,y,Xval, Yval, Xtest,ytest] = PRNGs(PRNGtype, n, v, t, d, k, featureType, labelSize, seed);
% Compute validation error with bootstrapped decision tree
depth = 4;
nTrees = 100;
model = randomForest(X,y,depth,nTrees);
yhat = model.predict(model,Xtest);
if(labelSize ==1 )
err(i) = sum(yhat ~= ytest)/t;
else
err(i) = 1-sum(all(yhat' == ytest'))/t;
end
disp(['iteration: ' num2str(i) ]);
fprintf('Average Error for Random Forest: %.04f \n', mean(err));
fprintf('Median Error for Random Forest: %.04f \n', median(err));
if(mod(i,100) == 0)
cdfplot(err);
pause(0.1);
end
end
fprintf('Average Error for Random Forest: %.04f \n', mean(err));
fprintf('Median Error for Random Forest: %.04f \n', median(err));
cdfplot(err);