コード例 #1
0
    def __init__(self,tuneID,params,data,queue):
        multiprocessing.Process.__init__(self)
        self.tuneID=tuneID
        self.model=CascadingModel(**params)
        #if transferLearning:

        self.data=data
        self.queue=queue
        self.params=params
コード例 #2
0
def testBestReRank(k,bestModel=None):
    if bestModel is None:
        model=CascadingModel(tasktype=modeltype,digtype=datatype)
    else:
        model=bestModel
    mymetric=model.mymetric
    mymetric.verbose=0
    taskids=data.taskids[:data.testPoint]
    Y_label=data.testLabel[:data.testPoint]

    print("tuning re-rank weight\n")
    best_param={3:0,5:0,10:0}
    rw=[w/10 for w in range(0,11)]
    rw.reverse()


    model.topK=k
    maxAcc=[0,0]
    model.loadConf()
    model.loadModel()
    Y_predict2=model.predict(data.testX,taskids)

    for w in rw:
            acc=mymetric.topKPDIGUsers(Y_predict2,Y_label,taskids,k,w)
            acc=np.mean(acc)
            if acc>maxAcc[0]:
                maxAcc=[acc,w]
                #print(data.tasktype,"top %d"%k,acc,"weight=%f"%(w/10))
    best_param[k]=maxAcc[1]
    print("\n",data.tasktype,"top %d"%k,maxAcc[0],"weight=%f"%maxAcc[1])
    print()
コード例 #3
0
def testCascadingModel():
    model=CascadingModel(tasktype=modeltype)
    taskids=data.taskids[:data.testPoint]
    Y_label=data.testLabel[:data.testPoint]
    Y_sublabel=data.submitLabelClassification[:data.testPoint]
    Y_reglabel=data.registerLabelClassification[:data.testPoint]
    mymetric=model.mymetric
    mymetric.callall=False

    print()

    print("\n meta-learning model top k acc")
    for k in (3,5,10):
        model.topK=k
        model.loadConf()
        model.loadModel()
        Y_predict2=model.predict(data.testX,taskids)
        #metrics
        acc=mymetric.topKPossibleUsers(Y_predict2,Y_label,k)
        acc=np.mean(acc)
        print(data.tasktype,"top %d"%k,acc)

        acc=mymetric.topKRUsers(Y_predict2,Y_label,Y_reglabel,k,)
        acc=np.mean(acc)
        print(data.tasktype,"top %d"%k,acc)

        acc=mymetric.topKSUsers(Y_predict2,Y_label,Y_sublabel,k,)
        acc=np.mean(acc)
        print(data.tasktype,"top %d"%k,acc)

        print()
コード例 #4
0
class TuneTask(multiprocessing.Process):
    maxProcessNum=32
    def __init__(self,tuneID,params,data,queue):
        multiprocessing.Process.__init__(self)
        self.tuneID=tuneID
        self.model=CascadingModel(**params)
        #if transferLearning:

        self.data=data
        self.queue=queue
        self.params=params

    def run(self):

        bestScore=0
        topDig=[w/10 for w in range(10,11)]
        topDig.reverse()
        tD=0
        #print("begin,%d"%self.tuneID)
        mymetric=self.model.mymetric
        taskids=self.data.taskids[self.data.validatePoint:]
        X=self.data.trainX
        Y_label=self.data.trainLabel
        for self.model.topDig in topDig:
            #print("predicting")
            Y=self.model.predict(X,taskids)
            Y=mymetric.topKPossibleUsers(Y,Y_label,self.model.topK)
            acc=np.mean(Y)
            #acc=self.model.score(self.data)
            #print(acc,"topDig=%f"%self.model.topDig)
            if acc>bestScore:
                tD=self.model.topDig
                bestScore=acc

        self.model.topDig=tD
        self.params["topDig"]=self.model.topDig

        #print("finished")
        #self.cond.acquire()
        self.queue.put([self.tuneID,self.model,bestScore,self.params])