From 28af3b75083382c29a56a34dc2f6e0051606e3c7 Mon Sep 17 00:00:00 2001 From: Joe Zhao Date: Wed, 3 Jun 2015 10:44:45 +0800 Subject: ensemble --- ensemble-train.py | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ misc.py | 31 +++++++++++++- 2 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 ensemble-train.py diff --git a/ensemble-train.py b/ensemble-train.py new file mode 100644 index 0000000..1ceb380 --- /dev/null +++ b/ensemble-train.py @@ -0,0 +1,124 @@ +from misc import * +import math +inr="a.rid" +resm="res.m" +#consts used +clist=[0.0001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 10, 100, 1000] + +folds=4 +tot=316 +step = tot // folds +inm="0.m" + +ourb=inr +#splits +print("splitting") +for i in range(folds-1): + inra=ourb + oura="a%d.rid"%i + ourb="b%d.rid"%i + params = "-c %d -i %s -a %s -b %s" %(step,inra,oura,ourb) + split(params) + +entries=['0','0'] + +tmp=take("b0.rid") +put("c0.rid",tmp) + +tmp=take("b%d.rid"%(folds-2)) +put("a%d.rid"%(folds-1),tmp) +print("merging") +for a in range(folds-1): + tmp=take("a%d.rid"%a) + entries = merge(tmp,entries) + + if a0: + low=1e20 + k=0 + P=[] + #find best weak ranker + for w in wlist: + t=0 + pr=getpred(w+".p") + for (d,p) in zip(D,pr): + if p<=0: + t+=d + if t