def savetovwfile(finelabels,coarselabels,data): for x in range(len(finelabels)): d = data[x] fl = finelabels[x] cl = coarselabels[x] u.appendfile(o.vwtrainline(fl,list(d),1),cifardir+"finedata") u.appendfile(o.vwtrainline(cl,list(d),1),cifardir+"coarsedata")
def makefile(data,labels,labelname): num = 0 for y in range(50000/500): chunk = [] for z in range(500): d = list(data[num]) l = labels[num] label = str(l)+" | " features = " ".join([str(x[0])+":"+str(x[1]) for x in zip(range(len(d)),d)]) chunk.append(label+features) num = num + 1 u.appendfile("\n".join(chunk), cifar100.cifardir+"vwtraindata"+labelname)
def test(): data = [[x for y in range(5)] for x in range(10)] for x in data: u.appendfile(vwtrainline(x[0],x,10), "/home/umar/testdata1") print trainvwinitial("/home/umar/testreg1",3, "/home/umar/testdata1") time.sleep(5) startvwpredictor("/home/umar/testreg1") for x in data: time.sleep(2) print "predicting ",x[0]," : ",vwpredict(x,10) killvw() subprocess.call(["rm","/home/umar/testdata1.cache"]) subprocess.call(["rm","/home/umar/testdata1"]) subprocess.call(["rm","/home/umar/testreg1"])