-
Notifications
You must be signed in to change notification settings - Fork 52
/
randomforest.q
28 lines (23 loc) · 1.06 KB
/
randomforest.q
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
\c 20 100
\l funq.q
\l wdbc.q
\l winequality.q
-1"applying random forest to the wdbc data set";
k:20
d:.ut.part[`train`test!3 1;0N?] wdbc.t
-1"bagging grows B decision trees with random sampling (with replacement)";
m:.ml.bag[k;.ml.q45[();::]] d`train
avg d.test.diagnosis=.ml.pbag[k;m] d`test
-1"a random forest grows B decision trees with random sampling (with replacement)";
-1"and a sub-selection of sqrt (for classification) of the features at each split";
m:.ml.bag[k;.ml.q45[(1#`maxff)!1#sqrt;::]] d`train
avg d.test.diagnosis=.ml.pbag[k;m] d`test
-1"applying random forest to the winequality data set";
d:.ut.part[`train`test!1 1;0N?] winequality.red.t
-1"bagging grows B decision trees with random sampling (with replacement)";
m:.ml.bag[k;.ml.rt[();::]] d`train
.ml.rms d.test.quality-.ml.pbag[k;m] d`test
-1"a random forest grows B decision trees with random sampling (with replacement)";
-1"and a sub-selection of one third (for regression) of the features at each split";
m:.ml.bag[k;.ml.rt[(1#`maxff)!1#%[;3];::]] d`train
.ml.rms d.test.quality-.ml.pbag[k;m] d`test