forked from BIDData/BIDMach
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyearprediction.ssc
executable file
·68 lines (51 loc) · 1.81 KB
/
yearprediction.ssc
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
60
61
62
63
64
65
66
67
68
:silent
import BIDMach.models.RandomForest
class xopts extends Learner.Options with MatDS.Opts with RandomForest.Opts with Batch.Opts
val opts = new xopts
val mdir = "/code/BIDMach/data/YearPrediction/"
val data = loadFMat(mdir+"train.fmat.lz4");
val cats = loadFMat(mdir+"cats.fmat.lz4");
val rr = rand(1,data.ncols);
val itrain = find(rr > 0.1f);
val itest = find(rr <= 0.1f);
val train = data(?,itrain);
val traincats = cats(?,itrain);
val test = data(?,itest);
val testcats = cats(?,itest);
val preds = zeros(testcats.nrows, testcats.ncols);
val ds = new MatDS(Array(train.asInstanceOf[Mat],traincats), opts);
val dsp = new MatDS(Array(test.asInstanceOf[Mat],preds), opts);
val nn = new Learner( // make a learner instance
ds, // datasource
new RandomForest(opts), // the model
null, // list of mixins or regularizers
new Batch(opts), // the optimization class to use
opts) // pass the options to the learner as well
val mm = new Learner( // make a predictor
dsp, // datasource
nn.model,
null,
null,
opts) // pass the options to the learner as well
opts.useGPU = true
opts.batchSize = 20000
opts.depth = 20
opts.ntrees = 25
opts.ncats = 90
opts.nsamps = 25
opts.nnodes = 250000
opts.nbits = 16
opts.gain = 0.001f
opts.regression = true
opts.autoReset = false
val rf = nn.model.asInstanceOf[RandomForest]
nn.train
opts.training=false
opts.putBack = 1
mm.predict
val rr=zeros(nn.results.ncols/opts.depth, opts.depth);
rr(?) = nn.results(0,?).t
val diffs = DMat(preds - testcats);
:silent
val scores = mean(rr)
val MSE = (diffs dotr diffs) / diffs.length;